把颜色值转成UIImageyu

来源:互联网 发布:dijkstra算法求解过程 编辑:程序博客网 时间:2024/06/06 18:04

//把颜色值转成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;


自定义的button,像登录时是否自动密码一样

    UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeCustom];

    btn.frame =CGRectMake(130,self.field_pwd.frame.origin.y+50, 150,40);

//    [btn setBackgroundImage:[UIImage imageNamed:@"btnuncheck"] forState:UIControlStateNormal];

//一定要用setImage才能成功

    [btn setImage:[UIImageimageNamed:@"btnuncheck"]forState:UIControlStateNormal];

    [btn setImage:[UIImageimageNamed:@"btncheck"]forState:UIControlStateSelected];

    [btn setTitle:@"记住密码"forState:UIControlStateNormal];

    [btn setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

    [self.viewaddSubview:btn];


//字的位置

- (CGRect)titleRectForContentRect:(CGRect)contentRect{

    returnCGRectMake(contentRect.origin.x+25, contentRect.origin.y, contentRect.size.width-25, contentRect.size.height);

}

//图片位置

- (CGRect)imageRectForContentRect:(CGRect)contentRect{

    returnCGRectMake(contentRect.origin.x, contentRect.origin.y,20, 20);

}



0 0