//把颜色值转成UIImage
- (UIImage*) createImageWithColor: (UIColor*) color
{
CGRect rect=CGRectMake(0.0f,0.0f, 1.0f,1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [colorCGColor]);
CGContextFillRect(context, rect);
UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(130, self.field_pwd.frame.origin.y+ 50, 150, 40);
// [btn setBackgroundImage:[UIImage imageNamed:@"btnuncheck"] forState:UIControlStateNormal];
//一定要用setImage才能成功
[btn setImage:[UIImage imageNamed:@"btnuncheck"] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:@"btncheck"] forState:UIControlStateSelected];
[btn setTitle:@"记住密码" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.view addSubview:btn];
//字的位置
- (CGRect)titleRectForContentRect:(CGRect)contentRect{
return CGRectMake(contentRect.origin.x+25, contentRect.origin.y, contentRect.size.width-25, contentRect.size.height);
}
//图片位置
- (CGRect)imageRectForContentRect:(CGRect)contentRect{
return CGRectMake(contentRect.origin.x, contentRect.origin.y, 20, 20);
}