MNButton
MNButton是封装UIButton的对象,提供按钮创建、样式设置、事件绑定和手势注册等功能,构建和管理按钮组件。
new MNButton(config?: {})构造一个新的MNButton实例。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
config | {} | 否 | 配置对象。 |
类成员(Class members)
Section titled “类成员(Class members)”| 字段名 | 类型 | 说明 |
|---|---|---|
highlightColor | UIColor | 高亮颜色。 |
builtInProperty | string[] | 内置属性。 |
hexColorAlpha
Section titled “hexColorAlpha”static hexColorAlpha(hex: string, alpha: number): UIColor根据十六进制颜色和透明度创建UIColor。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
hex | string | 是 | 十六进制颜色字符串。 |
alpha | number | 是 | 透明度值。 |
- 类型:
UIColor - 语义:返回创建的UIColor对象。
hexColor
Section titled “hexColor”static hexColor(hex: string): UIColor根据十六进制颜色创建UIColor。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
hex | string | 是 | 十六进制颜色字符串。 |
- 类型:
UIColor - 语义:返回创建的UIColor对象。
setColor
Section titled “setColor”static setColor(button: UIButton, hexColor: string, alpha?: number): void设置按钮颜色。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
button | UIButton | 是 | 按钮对象。 |
hexColor | string | 是 | 十六进制颜色字符串。 |
alpha | number | 否 | 透明度值。 |
- 类型:
void - 语义:无返回值。
setTitle
Section titled “setTitle”static setTitle(button: UIButton, title: string, font?: number, bold?: boolean): void设置按钮标题。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
button | UIButton | 是 | 按钮对象。 |
title | string | 是 | 标题文本。 |
font | number | 否 | 字体大小。 |
bold | boolean | 否 | 是否粗体。 |
- 类型:
void - 语义:无返回值。
setImage
Section titled “setImage”static setImage(button: UIButton, path: string|NSData): void设置按钮图像。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
button | UIButton | 是 | 按钮对象。 |
path | string|NSData | 是 | 图像路径或NSData对象。 |
- 类型:
void - 语义:无返回值。
setOpacity
Section titled “setOpacity”static setOpacity(button: UIButton, opacity: number): void设置按钮透明度。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
button | UIButton | 是 | 按钮对象。 |
opacity | number | 是 | 透明度值。 |
- 类型:
void - 语义:无返回值。
setRadius
Section titled “setRadius”static setRadius(button: UIButton, radius?: number): void设置按钮圆角半径。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
button | UIButton | 是 | 按钮对象。 |
radius | number | 否 | 圆角半径。 |
- 类型:
void - 语义:无返回值。
setConfig
Section titled “setConfig”static setConfig(button: UIButton, config: { color: string, alpha: number, opacity: number, radius: number }): void设置按钮配置。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
button | UIButton | 是 | 按钮对象。 |
config | { color: string, alpha: number, opacity: number, radius: number } | 是 | 配置对象。 |
- 类型:
void - 语义:无返回值。
addClickAction
Section titled “addClickAction”static addClickAction(button: UIButton, target: object, selector: string): void添加点击动作。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
button | UIButton | 是 | 按钮对象。 |
target | object | 是 | 目标对象。 |
selector | string | 是 | 选择器方法名。 |
- 类型:
void - 语义:无返回值。
addPanGesture
Section titled “addPanGesture”static addPanGesture(button: UIButton, target: object, selector: string): void添加平移手势。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
button | UIButton | 是 | 按钮对象。 |
target | object | 是 | 目标对象。 |
selector | string | 是 | 选择器方法名。 |
- 类型:
void - 语义:无返回值。
addLongPressGesture
Section titled “addLongPressGesture”static addLongPressGesture(button: UIButton, target: object, selector: string): void添加长按手势。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
button | UIButton | 是 | 按钮对象。 |
target | object | 是 | 目标对象。 |
selector | string | 是 | 选择器方法名。 |
- 类型:
void - 语义:无返回值。
addSwipeGesture
Section titled “addSwipeGesture”static addSwipeGesture(button: UIButton, target: object, selector: string): void添加滑动手势。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
button | UIButton | 是 | 按钮对象。 |
target | object | 是 | 目标对象。 |
selector | string | 是 | 选择器方法名。 |
- 类型:
void - 语义:无返回值。
实例成员(Instance members)
Section titled “实例成员(Instance members)”| 字段名 | 类型 | 说明 |
|---|---|---|
superview | UIView | 父视图。 |
frame | CGRect | 框架。 |
bounds | CGRect | 边界。 |
center | CGPoint | 中心点。 |
window | UIWindow|undefined | 窗口。 |
gestureRecognizers | NSArray<UIGestureRecognizer>|UIGestureRecognizer[]|undefined | 手势识别器。 |
borderColor | CGColor | 边框颜色。 |
borderWidth | number | 边框宽度。 |
backgroundColor | UIColor | 背景颜色。 |
color | UIColor|string | 颜色。 |
colorString | string | 颜色字符串。 |
hidden | boolean | 是否隐藏。 |
autoresizingMask | number | 自动调整掩码。 |
opacity | number | 透明度。 |
radius | number | 圆角半径。 |
cornerRadius | number | 圆角半径。 |
currentTitle | string | 当前标题。 |
title | string | 标题。 |
currentTitleColor | UIColor | 当前标题颜色。 |
currentTitleColorString | string | 当前标题颜色字符串。 |
titleColor | UIColor | 标题颜色。 |
titleColorString | string | 标题颜色字符串。 |
currentImage | UIImage | 当前图像。 |
subviews | NSArray<UIView>|UIView[] | 子视图。 |
font | UIFont | 字体。 |
masksToBounds | boolean | 是否裁剪到边界。 |
setFrame
Section titled “setFrame”setFrame(x: number, y: number, width: number, height: number): void设置按钮的位置和尺寸。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
x | number | 是 | x坐标。 |
y | number | 是 | y坐标。 |
width | number | 是 | 宽度。 |
height | number | 是 | 高度。 |
- 类型:
void - 语义:无返回值。
setColor
Section titled “setColor”setColor(hexColor: string, alpha?: number): void设置按钮颜色。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
hexColor | string | 是 | 十六进制颜色字符串。 |
alpha | number | 否 | 透明度值。 |
- 类型:
void - 语义:无返回值。
setImageForState
Section titled “setImageForState”setImageForState(image: UIImage, state?: number): void为指定状态设置按钮图像。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
image | UIImage | 是 | 图像对象。 |
state | number | 否 | 按钮状态。 |
- 类型:
void - 语义:无返回值。
setImage
Section titled “setImage”setImage(image: UIImage, state?: number): void设置按钮图像。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
image | UIImage | 是 | 图像对象。 |
state | number | 否 | 按钮状态。 |
- 类型:
void - 语义:无返回值。
setTitleColorForState
Section titled “setTitleColorForState”setTitleColorForState(color: UIColor, state?: number): void为指定状态设置标题颜色。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
color | UIColor | 是 | 颜色对象。 |
state | number | 否 | 按钮状态。 |
- 类型:
void - 语义:无返回值。
setTitleColor
Section titled “setTitleColor”setTitleColor(color: UIColor, state?: number): void设置标题颜色。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
color | UIColor | 是 | 颜色对象。 |
state | number | 否 | 按钮状态。 |
- 类型:
void - 语义:无返回值。
setTitleForState
Section titled “setTitleForState”setTitleForState(title: string, state?: number): void为指定状态设置标题。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
title | string | 是 | 标题文本。 |
state | number | 否 | 按钮状态。 |
- 类型:
void - 语义:无返回值。
setTitle
Section titled “setTitle”setTitle(title: string, state?: number): void设置按钮标题。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
title | string | 是 | 标题文本。 |
state | number | 否 | 按钮状态。 |
- 类型:
void - 语义:无返回值。
addSubview
Section titled “addSubview”addSubview(view: UIView): void添加子视图。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
view | UIView | 是 | 子视图对象。 |
- 类型:
void - 语义:无返回值。
removeFromSuperview
Section titled “removeFromSuperview”removeFromSuperview(): void从父视图中移除。
- 类型:
void - 语义:无返回值。
bringSubviewToFront
Section titled “bringSubviewToFront”bringSubviewToFront(view: UIView): void将子视图移到最前面。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
view | UIView | 是 | 子视图对象。 |
- 类型:
void - 语义:无返回值。
sendSubviewToBack
Section titled “sendSubviewToBack”sendSubviewToBack(view: UIView): void将子视图移到最后面。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
view | UIView | 是 | 子视图对象。 |
- 类型:
void - 语义:无返回值。
isDescendantOfView
Section titled “isDescendantOfView”isDescendantOfView(view: UIView): boolean判断是否是指定视图的后代。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
view | UIView | 是 | 父视图对象。 |
- 类型:
boolean - 语义:返回是否是后代视图。
isDescendantOfStudyView
Section titled “isDescendantOfStudyView”isDescendantOfStudyView(): boolean判断是否是学习视图的后代。
- 类型:
boolean - 语义:返回是否是学习视图的后代。
isDescendantOfCurrentWindow
Section titled “isDescendantOfCurrentWindow”isDescendantOfCurrentWindow(): boolean判断是否是当前窗口的后代。
- 类型:
boolean - 语义:返回是否是当前窗口的后代。
setNeedsLayout
Section titled “setNeedsLayout”setNeedsLayout(): void标记需要重新布局。
- 类型:
void - 语义:无返回值。
layoutIfNeeded
Section titled “layoutIfNeeded”layoutIfNeeded(): void立即执行布局。
- 类型:
void - 语义:无返回值。
layoutSubviews
Section titled “layoutSubviews”layoutSubviews(): void布局子视图。
- 类型:
void - 语义:无返回值。
setNeedsDisplay
Section titled “setNeedsDisplay”setNeedsDisplay(): void标记需要重新显示。
- 类型:
void - 语义:无返回值。
sizeThatFits
Section titled “sizeThatFits”sizeThatFits(size: CGSize): CGSize计算适合的尺寸。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
size | CGSize | 是 | 建议尺寸。 |
- 类型:
CGSize - 语义:返回适合的尺寸。
addTargetActionForControlEvents
Section titled “addTargetActionForControlEvents”addTargetActionForControlEvents(target: object, action: string, controlEvent: UIControlEvents): void为控制事件添加目标动作。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
target | object | 是 | 目标对象。 |
action | string | 是 | 动作方法名。 |
controlEvent | UIControlEvents | 是 | 控制事件。 |
- 类型:
void - 语义:无返回值。
removeTargetActionForControlEvents
Section titled “removeTargetActionForControlEvents”removeTargetActionForControlEvents(target: object, action: string, controlEvent: UIControlEvents): void移除控制事件的目标动作。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
target | object | 是 | 目标对象。 |
action | string | 是 | 动作方法名。 |
controlEvent | UIControlEvents | 是 | 控制事件。 |
- 类型:
void - 语义:无返回值。
addClickAction
Section titled “addClickAction”addClickAction(target: object, selector: string): void添加点击动作。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
target | object | 是 | 目标对象。 |
selector | string | 是 | 选择器方法名。 |
- 类型:
void - 语义:无返回值。
addGestureRecognizer
Section titled “addGestureRecognizer”addGestureRecognizer(gestureRecognizer: UIGestureRecognizer): void添加手势识别器。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
gestureRecognizer | UIGestureRecognizer | 是 | 手势识别器对象。 |
- 类型:
void - 语义:无返回值。
removeGestureRecognizer
Section titled “removeGestureRecognizer”removeGestureRecognizer(gestureRecognizer: UIGestureRecognizer): void移除手势识别器。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
gestureRecognizer | UIGestureRecognizer | 是 | 手势识别器对象。 |
- 类型:
void - 语义:无返回值。
addPanGesture
Section titled “addPanGesture”addPanGesture(target: object, selector: string): void添加平移手势。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
target | object | 是 | 目标对象。 |
selector | string | 是 | 选择器方法名。 |
- 类型:
void - 语义:无返回值。
addLongPressGesture
Section titled “addLongPressGesture”addLongPressGesture(target: object, selector: string): void添加长按手势。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
target | object | 是 | 目标对象。 |
selector | string | 是 | 选择器方法名。 |
- 类型:
void - 语义:无返回值。
addSwipeGesture
Section titled “addSwipeGesture”addSwipeGesture(target: object, selector: string): void添加滑动手势。
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
target | object | 是 | 目标对象。 |
selector | string | 是 | 选择器方法名。 |
- 类型:
void - 语义:无返回值。