iOS macOS背景色 圆切角 边框色
UIColor *color1=[UIColor colorWithRed:155/255 green:255/255 blue:255/255 alpha:1];//方法1,使用 静态方法创建color _view1.backgroundColor=color1; UIColor *color2=[[UIColor alloc] initWithRed:222/255 green:213/255 blue:221/255 alpha:1];//方法2,使用 实例方法 创建color [_view2 setBackgroundColor:color2];
self.navigationController.navigationBar.backgroundColor = [UIColor colorWithRed:253/255.0 green:50/255.0 blue:58/255.0 alpha:1.0];
!!!!要加.0切记
//[UIColor colorWithRed:143/255.0 green:186/255.0 blue:55/255.0 alpha:1.0];//呼伦贝尔草原绿
//设置UIbutton的文字颜色
[btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
//设置UIbutton的文字大小和背景颜色
btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
[btn setBackgroundColor: [UIColor blueColor]];
//有些时候我们想让UIButton的title居左对齐,我们设置
btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;
但是问题又出来,此时文字会紧贴到做边框,我们可以设置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
使文字距离做边框保持10个像素的距离。
self.view.wantsLayer = YES;//相当于 [self.view setWantsLayer:YES];
//将图层的边框设置为圆脚 myWebView.layer.cornerRadius = 8; myWebView.layer.masksToBounds = YES; //给图层添加一个有色边框 myWebView.layer.borderWidth = 5; myWebView.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:1] CGColor];
macOS NSViewController 背景色添加
[self.view setWantsLayer:YES];
self.view.layer.backgroundColor = (__bridge CGColorRef _Nullable)([NSColor colorWithCalibratedRed:5.0 green:0.0 blue:255.0 alpha:1]);
或者 self.view.layer.backgroundColor = CGColorCreateGenericRGB(1.0, 0, 0, 1.0);
self.view.layer.backgroundColor = CGColorCreateGenericRGB(89/255.0, 142/255.0, 252/255.0, 1.0);
常规的:[NSColor redColor];
[NSColor colorWithRed:255.0-148.0 green:255.0-52.0 blue:255.0-50.0 alpha:1]
[NSColor colorWithRed:66.0 green:255.0 blue:255.0 alpha:1]
macOS NSView 背景色添加
- (void)drawRect:(NSRect)dirtyRect { [super drawRect:dirtyRect]; //cocoa方法的改变背景颜色 [[NSColor redColor] setFill]; NSRectFill(dirtyRect); // Drawing code here. }