<span style="font-size:12px;"> </span><span style="font-size:14px;">UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(40, 60, 100, 60)];</span>
<span style="font-size:14px;"> button.backgroundColor = [UIColor orangeColor];</span>
<span style="font-size:14px;"> button.enabled = NO;</span>
<span style="font-size:14px;"> [button addTarget:self action:@selector(onButton) forControlEvents:UIControlEventTouchUpInside];</span>
<span style="font-size:14px;"> [self.view addSubview:button];</span>
<span style="font-size:14px;"> }</span>
<span style="font-size:14px;"> - (void)onButton{</span>
<span style="font-size:14px;"> NSLog(@"button被点击"); }</span><span style="font-size:18px;"> </span>
<span style="font-size:14px;">//不会有输出结果,因为button的事件被禁用。</span>BOOL selected;
1.UIControlContentVerticalAlignmentCenter
2.UIControlContentVerticalAlignmentTop
3.UIControlContentVerticalAlignmentBottom
4.UIControlContentVerticalAlignmentFill
1.UIControlContentHorizontalAlignmentCenter
2.UIControlContentHorizontalAlignmentLeft
3.UIControlContentHorizontalAlignmentRight
4.UIControlContentHorizontalAlignmentFill
<span style="font-size: 24px;"> </span><span style="font-size:18px;">button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//控件在水平方向的布局位置</span>
<span style="font-size:18px;"> button.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;//控件在垂直方向的布局位置</span>
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/wow09_1225/article/details/46761881