标签:
UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, kScreenWidth, 44)];
headView.backgroundColor = [UIColor clearColor];
[self.view addSubview:headView];
UIButton *leftButon = [UIButton buttonWithType:UIButtonTypeCustom];
[leftButon setTitle:@"登录OTATO" forState:UIControlStateNormal];
leftButon.frame = CGRectMake(0, 0, kScreenWidth / 2, 44);
leftButon.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
leftButon.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);
/*
这里使用
button.titleLabel.textAlignment = NSTextAlignmentLeft; 这行代码是没有效果的,这只是让标签中的文本左对齐,但
并没有改变标签在按钮中的对齐方式。
所以,我们首先要使用
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 这行代码,把按钮的内容(控件)
的对齐方式修改为水平左对齐,但是这们会紧紧靠着左边,不好看,
所以我们还可以修改属性:
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
这行代码可以让按钮的内容(控件)距离左边10个像素,这样就好看多了
*/
[leftButon setImage:[UIImage imageNamed:@"arrow_left_white"] forState:UIControlStateNormal];
leftButon.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 100);
[headView addSubview:leftButon];
UIButton *rightButon = [UIButton buttonWithType:UIButtonTypeCustom];
[rightButon setTitle:@"/ 手机注册" forState:UIControlStateNormal];
rightButon.frame = CGRectMake(kScreenWidth / 2, 0, kScreenWidth / 2, 44);
rightButon.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[headView addSubview:rightButon];
[leftButon addTarget:self action:@selector(goToSingUpVC) forControlEvents:UIControlEventTouchUpInside];
标签:
原文地址:http://www.cnblogs.com/longjie8556264/p/5198800.html