zoukankan      html  css  js  c++  java
  • button设置边框遇到的问题

    最近有个需求,自己搞button,不用图片了

    button边框的设置,貌似用UIColor转的CGColor不行,有些比如灰色直接变成透明,只能转黑色,绿色等标准色。

    这里用自己的色生成CGColor了:

            CGFloat r = (CGFloat) 212/255.0;

            CGFloat g = (CGFloat) 212/255.0;

            CGFloat b = (CGFloat) 212/255.0;

            CGFloat a = (CGFloat) 1.0;

            CGFloat components[4] = {r,g,b,a};

            CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

            CGColorRef backgroundColor = (CGColorRef)[(id)CGColorCreate(colorSpace, components) autorelease];

            CGColorSpaceRelease(colorSpace);

            [button.layer setBorderColor:backgroundColor];

     

    另外一个问题,由于没有图片,设置按下效果的时候,直接设置background不行。因此用了个曲线的方法:使用UIColor自己生成 UIImage

    + (UIImage *) createImageWithColor: (UIColor *) color

    {

        CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

        UIGraphicsBeginImageContext(rect.size);

        CGContextRef context = UIGraphicsGetCurrentContext();

        CGContextSetFillColorWithColor(context, [color CGColor]);

        CGContextFillRect(context, rect);

        

        UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        return theImage;

    }

    调用的时候,这样就可以了,也可以自己生成highlight的图片:      

            UIImage *img = [UIImagecreateImageWithColor:[UIColorwhiteColor]];

            [button  setBackgroundImage:img forState:UIControlStateNormal];

     

  • 相关阅读:
    CentOS 7.x时间同步服务chrony配置详解
    Kerbernetes使用ConfigMap资源配置非铭感信息
    Kerbernetes的volume应用进阶
    Kerbernetes的volume基础应用
    Kerbernetes的Ingress资源管理
    Kerbernetes的Service资源管理
    Kerbernetes的Pod控制器
    一份较为详细的深度学习资料汇总
    相见恨晚的网站
    Bert 时代的创新(应用篇):Bert 在 NLP 各领域的
  • 原文地址:https://www.cnblogs.com/Peterahan/p/2931953.html
Copyright © 2011-2022 走看看