1,UIButton初始化
(1)initWithFrame
UIButton *btn = [ [UIButton alloc] initWithFrame:CGRectMake(10, 20, 30, 10)];
(2)initWithType
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
能定义的button类型:
typedef enum {
UIButtonTypeCustom = 0, 自定义风格 最常用
UIButtonTypeRoundedRect, 圆角矩形
UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做详细说明用
UIButtonTypeInfoLight, 亮色感叹号
UIButtonTypeInfoDark, 暗色感叹号
UIButtonTypeContactAdd, 十字加号按钮
} UIButtonType;
2,UIButton常用方法
//设置button在view上的位置
btn.frame = CGRectMake(20, 30, 300, 30);
//设置button背景色
btn.backgroundColor = [UIColor redColor];
//设置button填充图片
[btn setImage: [UIImage imageNamed : @“Com.png”] forState: UIControlStateNormal];
//设置button标题
[btn setTitle: @“Title” forState: UIControlStateNormal]; //按钮默认的文本
[btn1 setTitle:@"我被点了!" forState:UIControlStateHighlighted]; //点击时的文本
//添加按钮事件
[btn addTarget: self action: @selector(btnClick) forControlEvents: UIControlEventTouchUpInside]; //事件方法名字是btnClick
//点击时按钮发光,就是在按钮中间发亮光
btn1.showsTouchWhenHighlighted=YES;
3, forState
作用: 定义按钮的文字或图片在何种状态下才会显现
enum {
UIControlStateNormal = 0, 常规状态显现
UIControlStateHighlighted = 1 << 0, 高亮状态显现
UIControlStateDisabled = 1 << 1, 禁用的状态才会显现
UIControlStateSelected = 1 << 2, 选中状态
UIControlStateApplication = 0x00FF0000, 当应用程序标志时
UIControlStateReserved = 0xFF000000 为内部框架预留,可以不管他
};
4,forControlEvents
作用: 设置触发方式
typedef NS_OPTIONS(NSUInteger, UIControlEvents) {
UIControlEventTouchDown = 1 << 0, // 指鼠标左键按下(注:只是“按下”)的动作
UIControlEventTouchDownRepeat = 1 << 1, // 指鼠标左键连续多次重复按下(注:只是“按下”) 的动作,比如,鼠标连续双击、三击、……、多次连击。
说明:多次重复按下时,事件序列是这样的:
UIControlEventTouchDown ->
UIControlEventTouchUpInside ->
UIControlEventTouchDown ->
UIControlEventTouchDownRepeat ->
UIControlEventTouchUpInside ->
UIControlEventTouchDown ->
UIControlEventTouchDownRepeat ->
UIControlEventTouchUpInside ->
......
除了第一次按下外,后面每次摁下都是一个 UIControlEventTouchDown事件,然后紧跟一个 UIControlEventTouchDownRepeat事件。
UIControlEventTouchDragInside = 1 << 2, // 指按下鼠标,然后在控件边界范围内拖动。
UIControlEventTouchDragOutside = 1 << 3, // 与UIControlEventTouchDragInside不同的是,拖动 时,鼠标位于控件边界范围之外。但首先得有个 UIControlEventTouchDown事件,然后接一个 UIControlEventTouchDragInside事件,再接一个 UIControlEventTouchDragExit事件,这时,鼠标已 经位于控件外了,继续拖动就是 UIControlEventTouchDragOutside事件了。
UIControlEventTouchDragEnter = 1 << 4, // 指拖动动作中,从控件边界外到内时产生的事件。
UIControlEventTouchDragExit = 1 << 5, //指拖动动作中,从控件边界内到外时产生的事件。
UIControlEventTouchUpInside = 1 << 6, //指鼠标在控件范围内抬起,前提先得按下,即 UIControlEventTouchDown或 UIControlEventTouchDownRepeat事件。
UIControlEventTouchUpOutside = 1 << 7, //指鼠标在控件边界范围外抬起,前提先得按下,然后拖 动到控件外,即
UIControlEventTouchDown ->
UIControlEventTouchDragInside(n 个) ->
UIControlEventTouchDragExit ->
UIControlEventTouchDragOutside(n 个)
时间序列,再然后就是抬起鼠标,产生 UIControlEventTouchUpOutside事件。
UIControlEventTouchCancel = 1 << 8, //所有触摸取消事件,即一次触摸因为放上了太多手指而被取消,或者被上锁或者电话呼叫打断。
UIControlEventValueChanged = 1 << 12, // sliders, etc.
UIControlEventEditingDidBegin = 1 << 16, // UITextField
UIControlEventEditingChanged = 1 << 17,
UIControlEventEditingDidEnd = 1 << 18,
UIControlEventEditingDidEndOnExit = 1 << 19, // 'return key' ending editing
UIControlEventAllTouchEvents = 0x00000FFF, // for touch events
UIControlEventAllEditingEvents = 0x000F0000, // for UITextField
UIControlEventApplicationReserved = 0x0F000000, // range available for application use
UIControlEventSystemReserved = 0xF0000000, // range reserved for internal framework use
UIControlEventAllEvents = 0xFFFFFFFF
};
相关推荐
UIEdgeInsets是什么 UIEdgeInsets是什么?我们点进去看一下: typedef struct UIEdgeInsets { CGFloat top, left, bottom, right; // specify amount to inset (positive) for each of the edges....
使用方法: 1. 在需要用到的地方: #import "ImageTextButton.h" 定义按钮 @property (nonatomic, strong) ImageTextButton *imgTextButton; 2. 直接调用 self.imgTextButton = [[ImageTextButton alloc] ...
功能2:给UIButton设置各属性,包括frame、textLabel.font、textAlignment(此属性因没有提示,不推荐使用)以及四种状态下(nomal,hightlighted,selected,disabled)的image、title、titleColor、backgroudImage...
CK倒计时按钮 特征 计数时按钮被禁用 倒计时时按钮自动启用 ...计数时设置自定义背景颜色 支持自定义标题同时计数 例子 要运行示例项目, pod ... 在用户定义的运行时属性窗口中设置count 。 如果您想在用户单击按钮时开
灵活对齐按钮支持灵活的文本/图像对齐的 UIButton 子类。 默认的 UIButton 只支持水平对齐,图像左对齐,文本右对齐。 这有点受限制。 如果你想要右边的图像和左边的文本怎么办? 或者您希望它们垂直显示? 那么这个...
RZVibrantButton RZVibrantButton是一款时尚的按钮,具有使用Swift构建的iOS 8活力效果。... 一些基本属性,例如icon , text , font , alpha ,转角半径,边框宽度和背景颜色(无振动效果)都可以轻松更改。
同时支持UIView,UIImageView,UIButton和UILabel的单角切圆/选角拱形切圆/全角切圆,并且避免了UIImageView使用系统圆角所导致的离屏显的问题,以及确保图层对象的masksToBounds属性始终为NO,从而使项目中大量使用...
您可以通过在Podfile上添加以下命令来使用此库: pod "JTFadingInfoView"用法最简单的设置: CGRect frame = CGRectMake( 150 , 200 , 150 , 50 ); NSString *label = @" JTFadingInfoView! " ; JTFadingInfoView *
手写控件,frame,center和bounds属性 一、手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4)如果是button等控件,还需考虑控件的单击事件等 ...
用法将其与其他所有UIButton对象一起使用,并对其进行自定义以适合您的需求受新Clips应用程序记录按钮的启发,SquishButton是实现相同设计和行为的UIButton子类。 用法将其与其他所有UIButton对象一起使用,并对其...
这样你就可以使用 UIButton 的所有属性和方法。 当然,如有必要,您可以向标签添加触摸事件,也许我应该添加一个委托属性。 用法 只需将 Tag.h 和 Tag.m 拖到您的项目中即可。 Tag就像普通控件----启动它并把它作为...
特征应用具有强类型和自动补全功能的属性缓存属性子样式方便的String和UIButton扩展要求iOS 9.0以上/ tvOS 9.0以上Xcode 10.0以上用法这是使用Texstyle的基本示例: let text = Text ( value : " Hello, World :...
由于项目中经常用到这种上面是图片下面是文字的按钮,但是UIButton不支持此种布局。...demo里有详细的使用方法,通过设置不同属性可轻松实现多种按钮样式的实现,第一次上传项目,还请大家多多支持。
使用委托方法配置按钮 func circleMenu ( circleMenu : CircleMenu, willDisplay button : UIButton, atIndex : Int ) 使用属性配置CircleMenu @IBInspectable var buttonsCount : Int = 3 @IBInspectable var ...
UIButton类在使用时需要一行行的来设置属性,代码过于冗余。每个点击事件都要创建一个方法,不利于阅读。最新代码地址:https://github.com/Maricle1/ControlsPackage.git
* UILabel/UIImageView/UIButton等这些组件以及某些包含他们的系统组件都具有此属性,遇到这些组件,你只需要为其指定位置即可。大小就使用Intrinsic Content Size就行了。 * 上述系统控件都重写了UIView 中的 -...
使用方法: 1、storyboard中添加自己设置好的的 view 2、将自己设置的 view 的 class 设置为 InteractivePlayerView 3、设置属性和初始化方法等就可以正常使用了。 @IBOutlet var ipv: ...
什么是 NKToggleOverlayButton? NKToggleOverlayButton 是... 使用setOnImage:forState:和setOffImage:forState:方法(类似于 UIButton 的setImage:forState:方法)或使用titleLabel属性更改按钮的外观。 覆盖层可以是
没有要实现的方法,只要想应用属性,就只需要调用applyTheme() registerForThemeChanges()如果希望能够支持主题plist的实时更新,则可以选择调用applyTheme() 。 class ViewController : UIViewController , ...