使用变量iOS更改背景颜色 [英] Change background color with a variable iOS

查看:109
本文介绍了使用变量iOS更改背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用变量更改标签的背景颜色。

I want to change the background color of my label with a variable how can I do that ?

这是我的代码,但我想要一个变量而不是'redColor'

This is my code but I'd like to have a variable instead of 'redColor'

[publisherLabel setBackgroundColor:[UIColor redColor]];


推荐答案

变量与RGBA值的颜色。

Variable with color from an RGBA value.

UIColor *myColor = [UIColor colorWithRed:100.0/255.0 green:101.0/255.0 blue:102.0/255.0 alpha:1.0]];

您也可以使用HEX:

#define HEXCOLOR(c) [UIColor colorWithRed:((c>>24)&0xFF)/255.0 
 green:((c>>16)&0xFF)/255.0 
 blue:((c>>8)&0xFF)/255.0 
 alpha:((c)&0xFF)/255.0];

// usage:
UIColor* c = HEXCOLOR(0xff00ffff);

这篇关于使用变量iOS更改背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆