您的位置:首页 > 移动开发 > IOS开发

自定义的button在ios7下可见,在ios6下不可见的解决办法

2013-12-19 17:53 267 查看
实现下面的button



1.先自定义button
UIButton *tiJiaoBtn=[UIButtonbuttonWithType:UIButtonTypeCustom];
tiJiaoBtn.frame=CGRectMake(148,0,
210, 54);
tiJiaoBtn.tag=2;
[tiJiaoBtn addTarget:selfaction:@selector(buttonOnClick:)forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:tiJiaoBtn];

2.给btn上面加上图片

UIImageView *tiJiaoImageView = [[UIImageViewalloc]
initWithFrame:CGRectMake(0,0,210,
54)];
tiJiaoImageView.image = [UIImageimageNamed:@"tijiaoBtn"];
[tiJiaoBtn addSubview:tiJiaoImageView];
[tiJiaoImageView release];

3.在btn的图片上加上文字
UILabel *tijiaoLabel=[[UILabelalloc]initWithFrame:CGRectMake(0,0,
210, 54)];
tijiaoLabel.textColor=[UIColor whiteColor];
tijiaoLabel.font=[UIFontsystemFontOfSize:22 ];
tijiaoLabel.textAlignment=UITextAlignmentCenter;
tijiaoLabel.text=@"提交";
[tiJiaoImageView addSubview:tijiaoLabel];
[tijiaoLabel release];

这样的实现以后发现在ios7下button可见。可是在ios6下却不可见了。解决办法:让label的背景为透明,即让tijiaoLabel的背景为透明颜色

tijiaoLabel.backgroundColor = [UIColorclearColor];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐