首页 > 代码库 > IOS UIButton 常用方法介绍
IOS UIButton 常用方法介绍
// 创建按钮
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// 设置按钮标题
[button setTitle:@"触摸我!" forState:UIControlStateNormal];
// 根据标题长度自动决定按钮尺寸
[button sizeToFit];
// 将按钮布置在中心位置
button.center = self.view.center;
// 画面变化时按钮位置自动调整
button.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin;
// 设置按钮被触摸时响应方法
[button addTarget:self
action:@selector(buttonDidPush:)
forControlEvents:UIControlEventTouchUpInside];
本文出自 “深圳市联城通科技公司” 博客,谢绝转载!
IOS UIButton 常用方法介绍