objective C设置背景颜色
[statussetBackgroundColor:(NSColor*)]还有个点语法,试过几次都报错,求大神指点下,看看错误在哪能给点范例就非常感谢!...
[status setBackgroundColor:(NSColor *)]
还有个点语法,试过几次都报错,求大神指点下,看看错误在哪
能给点范例就非常感谢! 展开
还有个点语法,试过几次都报错,求大神指点下,看看错误在哪
能给点范例就非常感谢! 展开
3个回答
展开全部
objective C设置背景颜色可以直接通过代码修改View颜色实现,参考代码如下:
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0,self.view.frame.size.width, 300)];
view.backgroundColor=[self colorWithHexString:@"e26562"];
[self.view addSubview:view];
}
- (UIColor *) colorWithHexString: (NSString *)color
{
NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; // String should be 6 or 8 characters
if ([cString length] < 6)
{
return [UIColor clearColor];
}
// strip 0X if it appears
if ([cString hasPrefix:@"0X"])
cString = [cString substringFromIndex:2];
if ([cString hasPrefix:@"#"])
cString = [cString substringFromIndex:1];
if ([cString length] != 6)
return [UIColor clearColor];
// Separate into r, g, b substrings
NSRange range;
range.location = 0;
range.length = 2;
//r
NSString *rString = [cString substringWithRange:range];
//g
range.location = 2;
NSString *gString = [cString substringWithRange:range];
//b
range.location = 4;
NSString *bString = [cString substringWithRange:range];
// Scan values
unsigned int r, g, b;
[[NSScanner scannerWithString:rString] scanHexInt:&r];
[[NSScanner scannerWithString:gString] scanHexInt:&g];
[[NSScanner scannerWithString:bString] scanHexInt:&b];
return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0,self.view.frame.size.width, 300)];
view.backgroundColor=[self colorWithHexString:@"e26562"];
[self.view addSubview:view];
}
- (UIColor *) colorWithHexString: (NSString *)color
{
NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; // String should be 6 or 8 characters
if ([cString length] < 6)
{
return [UIColor clearColor];
}
// strip 0X if it appears
if ([cString hasPrefix:@"0X"])
cString = [cString substringFromIndex:2];
if ([cString hasPrefix:@"#"])
cString = [cString substringFromIndex:1];
if ([cString length] != 6)
return [UIColor clearColor];
// Separate into r, g, b substrings
NSRange range;
range.location = 0;
range.length = 2;
//r
NSString *rString = [cString substringWithRange:range];
//g
range.location = 2;
NSString *gString = [cString substringWithRange:range];
//b
range.location = 4;
NSString *bString = [cString substringWithRange:range];
// Scan values
unsigned int r, g, b;
[[NSScanner scannerWithString:rString] scanHexInt:&r];
[[NSScanner scannerWithString:gString] scanHexInt:&g];
[[NSScanner scannerWithString:bString] scanHexInt:&b];
return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
status不知道你这个是什么,如果你要对UIWindow进行设置的话,建议self.window.backgroundcolor=[uicolor redcolor],如果是对一个uiview设置背景颜色,就是uiview.backgroundcolor=[uicolor redcolor],谢谢
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果你要对UIWindow进行设置的话,建议self.window.backgroundcolor=[uicolor redcolor],如果是对一个uiview设置背景颜色,就是uiview.backgroundcolor=[uicolor redcolor],
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询