eXit_door 2013-07-16 09:30 采纳率: 0%
浏览 2737

从UISlider获取RGB颜色

改变UISLider的值使用方法:

@property (strong, nonatomic) IBOutlet UISlider *r;
@property (strong, nonatomic) IBOutlet UISlider *g;
@property (strong, nonatomic) IBOutlet UISlider *b;
@property (strong, nonatomic) IBOutlet UILabel *colorLabel;

- (void)viewDidLoad
{
    [super viewDidLoad];

    _r.minimumValue=0;
    _r.maximumValue=255;

    _g.minimumValue=0;
    _g.maximumValue=255;

    _b.minimumValue=0;
    _b.maximumValue=255;

    // Do any additional setup after loading the view, typically from a nib.
}

-(void)sliderValueChanged:(UISlider*)slider
{
    [_colorLabel setBackgroundColor:[UIColor colorWithRed:_r.value green:_g.value blue:_b.value alpha:1]];
}

谢谢~

  • 写回答

2条回答

  • lanhailvcao 2013-07-16 09:45
    关注

    设置颜色方法:

    -(void)sliderValueChanged:(UISlider*)slider
    {
        float r=[[NSString stringWithFormat:@"%.0f",_r.value] floatValue];
        float g=[[NSString stringWithFormat:@"%.0f",_g.value]floatValue];
        float b=[[NSString stringWithFormat:@"%.0f",_b.value]floatValue];
    
        UIColor *colorToSet=[UIColor colorWithRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1];
        [_colorLabel setBackgroundColor:colorToSet];
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?