实现下面的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];