LibMN

MNButton

LibMN中的MNButton对象API文档。

MNButton是封装UIButton的对象,提供按钮创建、样式设置、事件绑定和手势注册等功能,构建和管理按钮组件。

构造函数

new MNButton(config?: {})

构造一个新的MNButton实例。

参数名类型必填说明
config{}配置对象。

类成员(Class members)

属性

字段名类型说明
highlightColorUIColor高亮颜色。
builtInPropertystring[]内置属性。

方法

hexColorAlpha

类型
static hexColorAlpha(hex: string, alpha: number): UIColor
说明

根据十六进制颜色和透明度创建UIColor。

参数
参数名类型必填说明
hexstring十六进制颜色字符串。
alphanumber透明度值。
返回值
  • 类型:UIColor
  • 语义:返回创建的UIColor对象。

hexColor

类型
static hexColor(hex: string): UIColor
说明

根据十六进制颜色创建UIColor。

参数
参数名类型必填说明
hexstring十六进制颜色字符串。
返回值
  • 类型:UIColor
  • 语义:返回创建的UIColor对象。

setColor

类型
static setColor(button: UIButton, hexColor: string, alpha?: number): void
说明

设置按钮颜色。

参数
参数名类型必填说明
buttonUIButton按钮对象。
hexColorstring十六进制颜色字符串。
alphanumber透明度值。
返回值
  • 类型:void
  • 语义:无返回值。

setTitle

类型
static setTitle(button: UIButton, title: string, font?: number, bold?: boolean): void
说明

设置按钮标题。

参数
参数名类型必填说明
buttonUIButton按钮对象。
titlestring标题文本。
fontnumber字体大小。
boldboolean是否粗体。
返回值
  • 类型:void
  • 语义:无返回值。

setImage

类型
static setImage(button: UIButton, path: string|NSData): void
说明

设置按钮图像。

参数
参数名类型必填说明
buttonUIButton按钮对象。
pathstring|NSData图像路径或NSData对象。
返回值
  • 类型:void
  • 语义:无返回值。

setOpacity

类型
static setOpacity(button: UIButton, opacity: number): void
说明

设置按钮透明度。

参数
参数名类型必填说明
buttonUIButton按钮对象。
opacitynumber透明度值。
返回值
  • 类型:void
  • 语义:无返回值。

setRadius

类型
static setRadius(button: UIButton, radius?: number): void
说明

设置按钮圆角半径。

参数
参数名类型必填说明
buttonUIButton按钮对象。
radiusnumber圆角半径。
返回值
  • 类型:void
  • 语义:无返回值。

setConfig

类型
static setConfig(button: UIButton, config: { color: string, alpha: number, opacity: number, radius: number }): void
说明

设置按钮配置。

参数
参数名类型必填说明
buttonUIButton按钮对象。
config{ color: string, alpha: number, opacity: number, radius: number }配置对象。
返回值
  • 类型:void
  • 语义:无返回值。

addClickAction

类型
static addClickAction(button: UIButton, target: object, selector: string): void
说明

添加点击动作。

参数
参数名类型必填说明
buttonUIButton按钮对象。
targetobject目标对象。
selectorstring选择器方法名。
返回值
  • 类型:void
  • 语义:无返回值。

addPanGesture

类型
static addPanGesture(button: UIButton, target: object, selector: string): void
说明

添加平移手势。

参数
参数名类型必填说明
buttonUIButton按钮对象。
targetobject目标对象。
selectorstring选择器方法名。
返回值
  • 类型:void
  • 语义:无返回值。

addLongPressGesture

类型
static addLongPressGesture(button: UIButton, target: object, selector: string): void
说明

添加长按手势。

参数
参数名类型必填说明
buttonUIButton按钮对象。
targetobject目标对象。
selectorstring选择器方法名。
返回值
  • 类型:void
  • 语义:无返回值。

addSwipeGesture

类型
static addSwipeGesture(button: UIButton, target: object, selector: string): void
说明

添加滑动手势。

参数
参数名类型必填说明
buttonUIButton按钮对象。
targetobject目标对象。
selectorstring选择器方法名。
返回值
  • 类型:void
  • 语义:无返回值。

实例成员(Instance members)

属性

字段名类型说明
superviewUIView父视图。
frameCGRect框架。
boundsCGRect边界。
centerCGPoint中心点。
windowUIWindow|undefined窗口。
gestureRecognizersNSArray<UIGestureRecognizer>|UIGestureRecognizer[]|undefined手势识别器。
borderColorCGColor边框颜色。
borderWidthnumber边框宽度。
backgroundColorUIColor背景颜色。
colorUIColor|string颜色。
colorStringstring颜色字符串。
hiddenboolean是否隐藏。
autoresizingMasknumber自动调整掩码。
opacitynumber透明度。
radiusnumber圆角半径。
cornerRadiusnumber圆角半径。
currentTitlestring当前标题。
titlestring标题。
currentTitleColorUIColor当前标题颜色。
currentTitleColorStringstring当前标题颜色字符串。
titleColorUIColor标题颜色。
titleColorStringstring标题颜色字符串。
currentImageUIImage当前图像。
subviewsNSArray<UIView>|UIView[]子视图。
fontUIFont字体。
masksToBoundsboolean是否裁剪到边界。

方法

setFrame

类型
setFrame(x: number, y: number, width: number, height: number): void
说明

设置按钮的位置和尺寸。

参数
参数名类型必填说明
xnumberx坐标。
ynumbery坐标。
widthnumber宽度。
heightnumber高度。
返回值
  • 类型:void
  • 语义:无返回值。

setColor

类型
setColor(hexColor: string, alpha?: number): void
说明

设置按钮颜色。

参数
参数名类型必填说明
hexColorstring十六进制颜色字符串。
alphanumber透明度值。
返回值
  • 类型:void
  • 语义:无返回值。

setImageForState

类型
setImageForState(image: UIImage, state?: number): void
说明

为指定状态设置按钮图像。

参数
参数名类型必填说明
imageUIImage图像对象。
statenumber按钮状态。
返回值
  • 类型:void
  • 语义:无返回值。

setImage

类型
setImage(image: UIImage, state?: number): void
说明

设置按钮图像。

参数
参数名类型必填说明
imageUIImage图像对象。
statenumber按钮状态。
返回值
  • 类型:void
  • 语义:无返回值。

setTitleColorForState

类型
setTitleColorForState(color: UIColor, state?: number): void
说明

为指定状态设置标题颜色。

参数
参数名类型必填说明
colorUIColor颜色对象。
statenumber按钮状态。
返回值
  • 类型:void
  • 语义:无返回值。

setTitleColor

类型
setTitleColor(color: UIColor, state?: number): void
说明

设置标题颜色。

参数
参数名类型必填说明
colorUIColor颜色对象。
statenumber按钮状态。
返回值
  • 类型:void
  • 语义:无返回值。

setTitleForState

类型
setTitleForState(title: string, state?: number): void
说明

为指定状态设置标题。

参数
参数名类型必填说明
titlestring标题文本。
statenumber按钮状态。
返回值
  • 类型:void
  • 语义:无返回值。

setTitle

类型
setTitle(title: string, state?: number): void
说明

设置按钮标题。

参数
参数名类型必填说明
titlestring标题文本。
statenumber按钮状态。
返回值
  • 类型:void
  • 语义:无返回值。

addSubview

类型
addSubview(view: UIView): void
说明

添加子视图。

参数
参数名类型必填说明
viewUIView子视图对象。
返回值
  • 类型:void
  • 语义:无返回值。

removeFromSuperview

类型
removeFromSuperview(): void
说明

从父视图中移除。

返回值
  • 类型:void
  • 语义:无返回值。

bringSubviewToFront

类型
bringSubviewToFront(view: UIView): void
说明

将子视图移到最前面。

参数
参数名类型必填说明
viewUIView子视图对象。
返回值
  • 类型:void
  • 语义:无返回值。

sendSubviewToBack

类型
sendSubviewToBack(view: UIView): void
说明

将子视图移到最后面。

参数
参数名类型必填说明
viewUIView子视图对象。
返回值
  • 类型:void
  • 语义:无返回值。

isDescendantOfView

类型
isDescendantOfView(view: UIView): boolean
说明

判断是否是指定视图的后代。

参数
参数名类型必填说明
viewUIView父视图对象。
返回值
  • 类型:boolean
  • 语义:返回是否是后代视图。

isDescendantOfStudyView

类型
isDescendantOfStudyView(): boolean
说明

判断是否是学习视图的后代。

返回值
  • 类型:boolean
  • 语义:返回是否是学习视图的后代。

isDescendantOfCurrentWindow

类型
isDescendantOfCurrentWindow(): boolean
说明

判断是否是当前窗口的后代。

返回值
  • 类型:boolean
  • 语义:返回是否是当前窗口的后代。

setNeedsLayout

类型
setNeedsLayout(): void
说明

标记需要重新布局。

返回值
  • 类型:void
  • 语义:无返回值。

layoutIfNeeded

类型
layoutIfNeeded(): void
说明

立即执行布局。

返回值
  • 类型:void
  • 语义:无返回值。

layoutSubviews

类型
layoutSubviews(): void
说明

布局子视图。

返回值
  • 类型:void
  • 语义:无返回值。

setNeedsDisplay

类型
setNeedsDisplay(): void
说明

标记需要重新显示。

返回值
  • 类型:void
  • 语义:无返回值。

sizeThatFits

类型
sizeThatFits(size: CGSize): CGSize
说明

计算适合的尺寸。

参数
参数名类型必填说明
sizeCGSize建议尺寸。
返回值
  • 类型:CGSize
  • 语义:返回适合的尺寸。

addTargetActionForControlEvents

类型
addTargetActionForControlEvents(target: object, action: string, controlEvent: UIControlEvents): void
说明

为控制事件添加目标动作。

参数
参数名类型必填说明
targetobject目标对象。
actionstring动作方法名。
controlEventUIControlEvents控制事件。
返回值
  • 类型:void
  • 语义:无返回值。

removeTargetActionForControlEvents

类型
removeTargetActionForControlEvents(target: object, action: string, controlEvent: UIControlEvents): void
说明

移除控制事件的目标动作。

参数
参数名类型必填说明
targetobject目标对象。
actionstring动作方法名。
controlEventUIControlEvents控制事件。
返回值
  • 类型:void
  • 语义:无返回值。

addClickAction

类型
addClickAction(target: object, selector: string): void
说明

添加点击动作。

参数
参数名类型必填说明
targetobject目标对象。
selectorstring选择器方法名。
返回值
  • 类型:void
  • 语义:无返回值。

addGestureRecognizer

类型
addGestureRecognizer(gestureRecognizer: UIGestureRecognizer): void
说明

添加手势识别器。

参数
参数名类型必填说明
gestureRecognizerUIGestureRecognizer手势识别器对象。
返回值
  • 类型:void
  • 语义:无返回值。

removeGestureRecognizer

类型
removeGestureRecognizer(gestureRecognizer: UIGestureRecognizer): void
说明

移除手势识别器。

参数
参数名类型必填说明
gestureRecognizerUIGestureRecognizer手势识别器对象。
返回值
  • 类型:void
  • 语义:无返回值。

addPanGesture

类型
addPanGesture(target: object, selector: string): void
说明

添加平移手势。

参数
参数名类型必填说明
targetobject目标对象。
selectorstring选择器方法名。
返回值
  • 类型:void
  • 语义:无返回值。

addLongPressGesture

类型
addLongPressGesture(target: object, selector: string): void
说明

添加长按手势。

参数
参数名类型必填说明
targetobject目标对象。
selectorstring选择器方法名。
返回值
  • 类型:void
  • 语义:无返回值。

addSwipeGesture

类型
addSwipeGesture(target: object, selector: string): void
说明

添加滑动手势。

参数
参数名类型必填说明
targetobject目标对象。
selectorstring选择器方法名。
返回值
  • 类型:void
  • 语义:无返回值。
头文件API清单

正在加载...

协议:JSBMNButton,来源:-

On this page

构造函数类成员(Class members)属性方法hexColorAlpha类型说明参数返回值hexColor类型说明参数返回值setColor类型说明参数返回值setTitle类型说明参数返回值setImage类型说明参数返回值setOpacity类型说明参数返回值setRadius类型说明参数返回值setConfig类型说明参数返回值addClickAction类型说明参数返回值addPanGesture类型说明参数返回值addLongPressGesture类型说明参数返回值addSwipeGesture类型说明参数返回值实例成员(Instance members)属性方法setFrame类型说明参数返回值setColor类型说明参数返回值setImageForState类型说明参数返回值setImage类型说明参数返回值setTitleColorForState类型说明参数返回值setTitleColor类型说明参数返回值setTitleForState类型说明参数返回值setTitle类型说明参数返回值addSubview类型说明参数返回值removeFromSuperview类型说明返回值bringSubviewToFront类型说明参数返回值sendSubviewToBack类型说明参数返回值isDescendantOfView类型说明参数返回值isDescendantOfStudyView类型说明返回值isDescendantOfCurrentWindow类型说明返回值setNeedsLayout类型说明返回值layoutIfNeeded类型说明返回值layoutSubviews类型说明返回值setNeedsDisplay类型说明返回值sizeThatFits类型说明参数返回值addTargetActionForControlEvents类型说明参数返回值removeTargetActionForControlEvents类型说明参数返回值addClickAction类型说明参数返回值addGestureRecognizer类型说明参数返回值removeGestureRecognizer类型说明参数返回值addPanGesture类型说明参数返回值addLongPressGesture类型说明参数返回值addSwipeGesture类型说明参数返回值