写在前面
以下都是项目初期搭建UI中遇到的一些小细节问题,在此简单记录下来,方便以后查阅,大神不喜勿喷,请绕过哦~,后期会陆续更新项目实施大致框架及协同开发的一些相关信息,嘿嘿,给自己不任务了,哈哈
1.实现两个按钮之间的竖条分割符
法一:
UIView *vSeperater = [[UIView alloc] init];
vSeperater.frame = CGRectMake(kScreenWidth/2-1, -25, 1, 45);
vSeperater.backgroundColor = [UIColor whiteColor];
[btn addSubview:vSeperater];
法二:
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(kScreenWidth/2-1, -25, 1, 45);
bottomBorder.backgroundColor = [UIColor whiteColor].CGColor;
[btn.layer addSublayer:bottomBorder];
2.设置button字体颜色
下面代码是摘自网上的,个人适当的改下,注释的方法设置字体是不会起作用的
UIButton *customButton = [UIButton buttonWithType:UIButtonTypeCustom];
[customButton setTitleColor:_btnFontColor forState:UIControlStateNormal];
// customButton.titleLabel.textColor = _btnFontColor;
3.导航栏背景颜色和透明度设置
背景颜色设置
self.navigationController.navigationBar.barTintColor = kColorHeadPerson;
禁用透明度
self.navigationController.navigationBar.translucent = NO;
相应页面隐藏导航栏和底部tab栏
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.tabBarController.tabBar.hidden = NO;
}
4.imgview上button点击事件不起作用问题
cell上添加imgview,之后在该imgview上布局三个button,button的点击事件不起作用,解决方法:将imageview换成uiview,ok。主要代码如下:
UITableViewCell *cell = [[UITableViewCell alloc]init];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
UIView *superView = cell;
//充值,提现,资产
UIView *vBg = ({
UIView *view = [UIView new];
view.backgroundColor = [UIColor whiteColor];
[superView addSubview:view];
[view mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(superView.mas_left).offset(0);
make.right.equalTo(superView.mas_right).offset(0);
make.bottom.equalTo(superView.mas_bottom).offset(0);
make.height.equalTo(@60);
}];
view;
});
UIButton *btnCharge =({
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"充值" forState:UIControlStateNormal];
btn.titleLabel.font = SYSTEMFONT(22);
[btn setTintColor:kColorHeadPerson];
[btn addTarget:self action:@selector(clickCharge) forControlEvents:UIControlEventTouchUpInside];
[vBg addSubview:btn];
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(kScreenWidth/3-1, 20, 1, 25);
bottomBorder.backgroundColor = [UIColor lightGrayColor].CGColor;
[btn.layer addSublayer:bottomBorder];
btn;
});
UIButton *btnWithdraw =({
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"提现" forState:UIControlStateNormal];
btn.titleLabel.font = SYSTEMFONT(22);
[btn setTintColor:kColorHeadPerson];
[btn addTarget:self action:@selector(clickWithdraw) forControlEvents:UIControlEventTouchUpInside];
[vBg addSubview:btn];
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(kScreenWidth/3-1, 20, 1, 25);
bottomBorder.backgroundColor = [UIColor lightGrayColor].CGColor;
[btn.layer addSublayer:bottomBorder];
btn;
});
UIButton *btnAsset =({
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"资产" forState:UIControlStateNormal];
btn.titleLabel.font = SYSTEMFONT(22);
[btn setTintColor:kColorHeadPerson];
[btn addTarget:self action:@selector(clickAsset) forControlEvents:UIControlEventTouchUpInside];
[vBg addSubview:btn];
btn;
});
[btnCharge mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(vBg.mas_left);
make.right.equalTo(btnWithdraw.mas_left);
make.width.equalTo(btnAsset.mas_width);
make.width.equalTo(btnWithdraw.mas_width);
make.height.equalTo(vBg);
}];
[btnWithdraw mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(btnCharge.mas_right);
make.right.equalTo(btnAsset.mas_left);
make.width.equalTo(btnAsset.mas_width);
make.width.equalTo(btnCharge.mas_width);
make.height.equalTo(vBg);
}];
[btnAsset mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(btnWithdraw.mas_right);
make.right.equalTo(vBg.mas_right);
make.width.equalTo(btnCharge.mas_width);
make.width.equalTo(btnWithdraw.mas_width);
make.height.equalTo(vBg);
}];
return cell;
5.Masonry约束问题
关于Masonry约束问题编译报错:
在使用Masonry布局之前,确保subview已经被add父view上。
关于控制台显示约束出现问题,去fix it的时候,一般按照提示,给每个布局小部分打断点跟踪调试,一般就可以就解决。
6.button懒加载失败问题
把如下代码放在懒加载里面,页面上的button是出不来的,放在viewdidload里面是ok的,这里原因还不太清楚,应该跟懒加载的相关机制有关。
[self.btnFetchPwd mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.mas_left).offset(20);
make.right.equalTo(self.view.mas_right).offset(-20);
make.top.equalTo(self.tableview.mas_bottom).offset(20);
make.height.equalTo(@60);
}];