您的位置:首页 > 产品设计 > UI/UE

UIButton总结

2016-02-23 15:22 337 查看
概念:

UIButton的类是一个UIControl子类,它实现了在触摸屏上的按钮。触摸一个按钮拦截事件和动作消息发送到目标对象时,它的挖掘。设定的目标和行动方法都继承自UIControl。这个类提供了方法来设置标题,图像,按钮等外观属性。通过使用set方法,你可以指定一个不同的外观为每个按钮状态。

创建:

//创建圆角button

UIButton *button = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

//指定button的位置和大小

button.frame = CGRectMake(10, 10, 75, 75);

//给button设置标签,用来辨别点击的是哪个button,常用在委托方法中。

button.tag = 0;

//定义按钮标题

[button setTitle:@"Button Title" forState:UIControlStateNormal];

//定义按钮标题字体格式

[button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];

//给button添加委托方法,即点击触发的事件。

[button addTarget:selfaction:@selector(touchButton1:) forControlEvents :UIControl EventTouchUp Inside];

//给button添加图片

[button setImage:[UIImageimageNamed:@"blue_bg(2).png"] forState:UIControlStateNormal];

//将button加入视图当中

[view addSubview:button];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: