Skip to content

MNButton

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

new MNButton(config?: {})

构造一个新的MNButton实例。

参数名类型必填说明
config{}配置对象。
字段名类型说明
highlightColorUIColor高亮颜色。
builtInPropertystring[]内置属性。
static hexColorAlpha(hex: string, alpha: number): UIColor

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

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

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

参数名类型必填说明
hexstring十六进制颜色字符串。
  • 类型:UIColor
  • 语义:返回创建的UIColor对象。
static setColor(button: UIButton, hexColor: string, alpha?: number): void

设置按钮颜色。

参数名类型必填说明
buttonUIButton按钮对象。
hexColorstring十六进制颜色字符串。
alphanumber透明度值。
  • 类型:void
  • 语义:无返回值。
static setTitle(button: UIButton, title: string, font?: number, bold?: boolean): void

设置按钮标题。

参数名类型必填说明
buttonUIButton按钮对象。
titlestring标题文本。
fontnumber字体大小。
boldboolean是否粗体。
  • 类型:void
  • 语义:无返回值。
static setImage(button: UIButton, path: string|NSData): void

设置按钮图像。

参数名类型必填说明
buttonUIButton按钮对象。
pathstring|NSData图像路径或NSData对象。
  • 类型:void
  • 语义:无返回值。
static setOpacity(button: UIButton, opacity: number): void

设置按钮透明度。

参数名类型必填说明
buttonUIButton按钮对象。
opacitynumber透明度值。
  • 类型:void
  • 语义:无返回值。
static setRadius(button: UIButton, radius?: number): void

设置按钮圆角半径。

参数名类型必填说明
buttonUIButton按钮对象。
radiusnumber圆角半径。
  • 类型:void
  • 语义:无返回值。
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
  • 语义:无返回值。
static addClickAction(button: UIButton, target: object, selector: string): void

添加点击动作。

参数名类型必填说明
buttonUIButton按钮对象。
targetobject目标对象。
selectorstring选择器方法名。
  • 类型:void
  • 语义:无返回值。
static addPanGesture(button: UIButton, target: object, selector: string): void

添加平移手势。

参数名类型必填说明
buttonUIButton按钮对象。
targetobject目标对象。
selectorstring选择器方法名。
  • 类型:void
  • 语义:无返回值。
static addLongPressGesture(button: UIButton, target: object, selector: string): void

添加长按手势。

参数名类型必填说明
buttonUIButton按钮对象。
targetobject目标对象。
selectorstring选择器方法名。
  • 类型:void
  • 语义:无返回值。
static addSwipeGesture(button: UIButton, target: object, selector: string): void

添加滑动手势。

参数名类型必填说明
buttonUIButton按钮对象。
targetobject目标对象。
selectorstring选择器方法名。
  • 类型:void
  • 语义:无返回值。
字段名类型说明
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(x: number, y: number, width: number, height: number): void

设置按钮的位置和尺寸。

参数名类型必填说明
xnumberx坐标。
ynumbery坐标。
widthnumber宽度。
heightnumber高度。
  • 类型:void
  • 语义:无返回值。
setColor(hexColor: string, alpha?: number): void

设置按钮颜色。

参数名类型必填说明
hexColorstring十六进制颜色字符串。
alphanumber透明度值。
  • 类型:void
  • 语义:无返回值。
setImageForState(image: UIImage, state?: number): void

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

参数名类型必填说明
imageUIImage图像对象。
statenumber按钮状态。
  • 类型:void
  • 语义:无返回值。
setImage(image: UIImage, state?: number): void

设置按钮图像。

参数名类型必填说明
imageUIImage图像对象。
statenumber按钮状态。
  • 类型:void
  • 语义:无返回值。
setTitleColorForState(color: UIColor, state?: number): void

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

参数名类型必填说明
colorUIColor颜色对象。
statenumber按钮状态。
  • 类型:void
  • 语义:无返回值。
setTitleColor(color: UIColor, state?: number): void

设置标题颜色。

参数名类型必填说明
colorUIColor颜色对象。
statenumber按钮状态。
  • 类型:void
  • 语义:无返回值。
setTitleForState(title: string, state?: number): void

为指定状态设置标题。

参数名类型必填说明
titlestring标题文本。
statenumber按钮状态。
  • 类型:void
  • 语义:无返回值。
setTitle(title: string, state?: number): void

设置按钮标题。

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

添加子视图。

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

从父视图中移除。

  • 类型:void
  • 语义:无返回值。
bringSubviewToFront(view: UIView): void

将子视图移到最前面。

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

将子视图移到最后面。

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

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

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

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

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

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

  • 类型:boolean
  • 语义:返回是否是当前窗口的后代。
setNeedsLayout(): void

标记需要重新布局。

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

立即执行布局。

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

布局子视图。

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

标记需要重新显示。

  • 类型:void
  • 语义:无返回值。
sizeThatFits(size: CGSize): CGSize

计算适合的尺寸。

参数名类型必填说明
sizeCGSize建议尺寸。
  • 类型:CGSize
  • 语义:返回适合的尺寸。
addTargetActionForControlEvents(target: object, action: string, controlEvent: UIControlEvents): void

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

参数名类型必填说明
targetobject目标对象。
actionstring动作方法名。
controlEventUIControlEvents控制事件。
  • 类型:void
  • 语义:无返回值。
removeTargetActionForControlEvents(target: object, action: string, controlEvent: UIControlEvents): void

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

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

添加点击动作。

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

添加手势识别器。

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

移除手势识别器。

参数名类型必填说明
gestureRecognizerUIGestureRecognizer手势识别器对象。
  • 类型:void
  • 语义:无返回值。
addPanGesture(target: object, selector: string): void

添加平移手势。

参数名类型必填说明
targetobject目标对象。
selectorstring选择器方法名。
  • 类型:void
  • 语义:无返回值。
addLongPressGesture(target: object, selector: string): void

添加长按手势。

参数名类型必填说明
targetobject目标对象。
selectorstring选择器方法名。
  • 类型:void
  • 语义:无返回值。
addSwipeGesture(target: object, selector: string): void

添加滑动手势。

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

正在加载…

协议:,来源: