iOS button label 透明色
// // ViewController.m // 7.13蓝牙 // // Created by computer on 16/7/13. // Copyright © 2016年 computer. All rights reserved. // #import "ViewController.h" #import "BLEManager.h"//蓝牙中心控制管理界面 #import "musicVC.h" #import "FMVC.h" #import "line_inVC.h" #import "PC_VC.h" #import "BT_VC.h" @interface ViewController ()
@property(nonatomic ,strong)UIButton *btnmusic;
@property(nonatomic ,strong)UIButton *btnFm;
@property(nonatomic ,strong)UIButton *btnline;
@property(nonatomic ,strong)UIButton *btnPC;
@property(nonatomic ,strong)UIButton *btnBT; @property(nonatomic ,strong)UILabel *txtmusic; @property(nonatomic ,strong)UILabel *txtFM; @property(nonatomic ,strong)UILabel *txtline_in; @property(nonatomic ,strong)UILabel *txtPC; @property(nonatomic ,strong)UILabel *txtBT; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title=@"控制中心⌨️"; // 设置背景图片 UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0,64,fDeviceWidth,fDeviceHeight-64)]; imageView.image=[UIImage imageNamed:@"book_bg.jpg"]; [self.view insertSubview:imageView atIndex:0]; // 创建菜单按钮 [self setButton_name:self.btnmusic btn_x:fDeviceWidth*0.2 btn_y:fDeviceHeight/7+44 btn_w:fDeviceWidth*0.2 btn_h:fDeviceHeight*2/21 btnNormalimage:@"book_music.png" btnHighimage:@"LOGO_2.png" btnClick:@"btn1"]; [self setButton_name:self.btnFM btn_x:fDeviceWidth*0.6 btn_y:fDeviceHeight/7+44 btn_w:fDeviceWidth*0.2 btn_h:fDeviceHeight*2/21 btnNormalimage:@"book_FM.png" btnHighimage:@"LOGO_2" btnClick:@"btn2"]; [self setButton_name:self.btnline_in btn_x:fDeviceWidth*0.2 btn_y:fDeviceHeight*3/7+44 btn_w:fDeviceWidth*0.2 btn_h:fDeviceHeight*2/21 btnNormalimage:@"book_line_in.png" btnHighimage:@"LOGO_2" btnClick:@"btn3"]; [self setButton_name:self.btnPC btn_x:fDeviceWidth*0.6 btn_y:fDeviceHeight*3/7+44 btn_w:fDeviceWidth*0.2 btn_h:fDeviceHeight*2/21 btnNormalimage:@"book_PC.png" btnHighimage:@"LOGO_2" btnClick:@"btn4"]; [self setButton_name:self.btnBT btn_x:fDeviceWidth*0.2 btn_y:fDeviceHeight*5/7+44 btn_w:fDeviceWidth*0.2 btn_h:fDeviceHeight*2/21 btnNormalimage:@"book_BT.png" btnHighimage:@"LOGO_2" btnClick:@"btn5"]; [self setButton_name:self.btnBT btn_x:fDeviceWidth*0.6 btn_y:fDeviceHeight*5/7+44 btn_w:fDeviceWidth*0.2 btn_h:fDeviceHeight*2/21 btnNormalimage:@"book_switch.png" btnHighimage:@"LOGO_2" btnClick:@"btn6"]; // 创建按钮标签 [self setLabel_name:self.txtmusic lbl_x:fDeviceWidth*0.2 lbl_y:fDeviceHeight*5/21+44 lbl_w:fDeviceWidth*0.2 lbl_h:fDeviceHeight*1/21 lbltext:@"音乐模式" lbltextbgc:[UIColor colorWithWhite:0.f alpha:0] lbltxtcolor:[UIColor whiteColor] lblfont:[UIFont fontWithName:@"Arial" size:15.0] lblcornerRadius:0 lblmasksToBounds:YES lbltextAlignment:NSTextAlignmentCenter]; [self setLabel_name:self.txtFM lbl_x:fDeviceWidth*0.6 lbl_y:fDeviceHeight*5/21+44 lbl_w:fDeviceWidth*0.2 lbl_h:fDeviceHeight*1/21 lbltext:@"FM模式" lbltextbgc:[UIColor colorWithWhite:0.f alpha:0] lbltxtcolor:[UIColor whiteColor] lblfont:[UIFont fontWithName:@"Arial" size:15.0] lblcornerRadius:0 lblmasksToBounds:YES lbltextAlignment:NSTextAlignmentCenter]; [self setLabel_name:self.txtline_in lbl_x:fDeviceWidth*0.2 lbl_y:fDeviceHeight*11/21+44 lbl_w:fDeviceWidth*0.2 lbl_h:fDeviceHeight*1/21 lbltext:@"ling_in模式" lbltextbgc:[UIColor colorWithWhite:0.f alpha:0] lbltxtcolor:[UIColor whiteColor] lblfont:[UIFont fontWithName:@"Arial" size:15.0] lblcornerRadius:0 lblmasksToBounds:YES lbltextAlignment:NSTextAlignmentCenter]; [self setLabel_name:self.txtPC lbl_x:fDeviceWidth*0.6 lbl_y:fDeviceHeight*11/21+44 lbl_w:fDeviceWidth*0.2 lbl_h:fDeviceHeight*1/21 lbltext:@"PC模式" lbltextbgc:[UIColor colorWithWhite:0.f alpha:0] lbltxtcolor:[UIColor whiteColor] lblfont:[UIFont fontWithName:@"Arial" size:15.0] lblcornerRadius:0 lblmasksToBounds:YES lbltextAlignment:NSTextAlignmentCenter]; [self setLabel_name:self.txtBT lbl_x:fDeviceWidth*0.2 lbl_y:fDeviceHeight*17/21+44 lbl_w:fDeviceWidth*0.2 lbl_h:fDeviceHeight*1/21 lbltext:@"BT模式" lbltextbgc:[UIColor colorWithWhite:0.f alpha:0] lbltxtcolor:[UIColor whiteColor] lblfont:[UIFont fontWithName:@"Arial" size:15.0] lblcornerRadius:0 lblmasksToBounds:YES lbltextAlignment:NSTextAlignmentCenter]; [self setLabel_name:self.txtBT lbl_x:fDeviceWidth*0.6 lbl_y:fDeviceHeight*17/21+44 lbl_w:fDeviceWidth*0.2 lbl_h:fDeviceHeight*1/21 lbltext:@"切换模式" lbltextbgc:[UIColor colorWithWhite:0.f alpha:0] lbltxtcolor:[UIColor whiteColor] lblfont:[UIFont fontWithName:@"Arial" size:15.0] lblcornerRadius:0 lblmasksToBounds:YES lbltextAlignment:NSTextAlignmentCenter]; } #pragma mark - 创建按钮 -(void)setButton_name:(UIButton *)btnname btn_x:(int)btnX btn_y:(int)btnY btn_w:(int)btnW btn_h:(int)btnH btnNormalimage:(NSString *)norimgname btnHighimage:(NSString *)highimaname btnClick:btnClicksth{ // 初始化按钮 btnname=[UIButton buttonWithType:UIButtonTypeCustom]; // 设定按钮位置宽高 btnname.frame=CGRectMake(btnX,btnY,btnW,btnH); // 正常状态下按钮图片 [btnname setBackgroundImage:[UIImage imageNamed:norimgname] forState:UIControlStateNormal]; // 高亮就是按下按钮时的图片 [btnname setBackgroundImage:[UIImage imageNamed:highimaname] forState:UIControlStateHighlighted];
// 设定按钮背景色
[rightbutton setBackgroundColor:[UIColor colorWithRed:163.0/255.0 green:36.0/255.0 blue:227.0/255.0 alpha:1.0]];
// 设定按钮文字,大小,颜色
[btnname setTitle:btntxt forState: UIControlStateNormal];
btnname.titleLabel.font = [UIFont systemFontOfSize: 14.0];
[btnname setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//边框宽度
[btnname.layer setBorderWidth:1.0];
btnname.layer.borderColor=[UIColor whiteColor].CGColor;
//切圆角
button.clipsToBounds=YES;
button.layer.cornerRadius=30;//这里的30是你想设置的圆角大小,比如是一个40*40的正方形,那个设置成20就是一个圆,以此类推
//maoOS圆切角
[_btn.layer setCornerRadius:16];
[_btn.layer setMasksToBounds:YES];
// 按钮添加阴影
button.layer.shadowColor = [UIColor blackColor].CGColor;
button.layer.shadowOffset = CGSizeMake(5, 5);
button.layer.shadowRadius = 5;
button.layer.shadowOpacity = 0.5;
// 按钮事件方法 if ([btnClicksth isEqualToString:@"btn1"]) { [btnname addTarget:self action:@selector(btn1Click:) forControlEvents:UIControlEventTouchUpInside]; }else if ([btnClicksth isEqualToString:@"btn2"]){ [btnname addTarget:self action:@selector(btn2Click:) forControlEvents:UIControlEventTouchUpInside]; }else if ([btnClicksth isEqualToString:@"btn3"]){ [btnname addTarget:self action:@selector(btn3Click:) forControlEvents:UIControlEventTouchUpInside]; }else if ([btnClicksth isEqualToString:@"btn4"]){ [btnname addTarget:self action:@selector(btn4Click:) forControlEvents:UIControlEventTouchUpInside]; }else if ([btnClicksth isEqualToString:@"btn5"]){ [btnname addTarget:self action:@selector(btn5Click:) forControlEvents:UIControlEventTouchUpInside]; }else if ([btnClicksth isEqualToString:@"btn6"]){ [btnname addTarget:self action:@selector(btn6Click:) forControlEvents:UIControlEventTouchUpInside]; }else{ [btnname addTarget:self action:@selector(btn0Click:) forControlEvents:UIControlEventTouchUpInside]; } btnname.clipsToBounds=YES; btnname.layer.cornerRadius=15;//这里的30是你想设置的圆角大小,比如是一个40*40的正方形,那个设置成20就是一个圆,以此类推 // 在视图中加载出来按钮 [self.view addSubview:btnname]; } #pragma mark 创建文字 -(void)setLabel_name:(UILabel *)lblname lbl_x:(int)lblX lbl_y:(int)lblY lbl_w:(int)lblW lbl_h:(int)lblH lbltext:(NSString *)lbltxt lbltextbgc:(UIColor *)bgcolor lbltxtcolor:(UIColor *)lblcolor lblfont:(UIFont *)lblfont lblcornerRadius:(int)lblradius lblmasksToBounds:(BOOL)lblmTB lbltextAlignment:(NSTextAlignment)lblAlignment{ // 初始化Label标签 lblname=[[UILabel alloc]initWithFrame:CGRectMake(lblX, lblY, lblW,lblH)]; lblname.text=lbltxt;//标签内容 lblname.backgroundColor=bgcolor;//标签背景色彩 lblname.textColor=lblcolor;//标签色彩 lblname.font=lblfont;//标签类型大小 lblname.layer.cornerRadius=lblradius;//设置myLabel的圆角半径为25,刚好是高度的一半。这样的话myLabel的左右两侧就是半圆。 lblname.layer.masksToBounds=lblmTB; lblname.textAlignment=lblAlignment;//对齐方式为居中对齐
lblname.numberOfLines = 0;//表示label可以多行显示
[self.view addSubview:lblname];// 在视图中加载出来按钮 } #pragma mark 隐藏顶上的信号 //-(void)viewWillAppear:(BOOL)animated //{ // [super viewWillAppear:animated]; // // [self.navigationController setNavigationBarHidden:YES animated:YES]; //} // //-(void)viewWillDisappear:(BOOL)animated //{ // [super viewWillAppear:animated]; // // [self.navigationController setNavigationBarHidden:NO animated:YES]; //} #pragma mark 按钮事件 -(void)btn0Click:(UIButton *)sender{ NSLog(@"请设置菜单事件"); } -(void)btn1Click:(UIButton *)sender{ NSLog(@"你点击了音乐模式"); musicVC *ShowmusicVC=[[musicVC alloc]init]; [self.navigationController pushViewController:ShowmusicVC animated:NO]; } -(void)btn2Click:(UIButton *)sender{ NSLog(@"你点击了FM模式"); FMVC *ShowFMVC=[[FMVC alloc]init]; [self.navigationController pushViewController:ShowFMVC animated:NO]; } -(void)btn3Click:(UIButton *)sender{ NSLog(@"你点击了line_in模式"); line_inVC *Showline_inVC=[[line_inVC alloc]init]; [self.navigationController pushViewController:Showline_inVC animated:NO]; } -(void)btn4Click:(UIButton *)sender{ NSLog(@"你点击了PC模式"); PC_VC *ShowPC_VC=[[PC_VC alloc]init]; [self.navigationController pushViewController:ShowPC_VC animated:NO]; } -(void)btn5Click:(UIButton *)sender{ NSLog(@"你点击了BT模式"); BT_VC *ShowBT_VC=[[BT_VC alloc]init]; [self.navigationController pushViewController:ShowBT_VC animated:NO]; } -(void)btn6Click:(UIButton *)sender{ NSLog(@"你点击了切换模式"); [KBLEManager choose_model]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
macos
// return [NSColor colorWithCalibratedRed:((float)r/255.0) green:((float)g/255.0) blue:((float)b/255.0) alpha:1.0]; return [NSColor colorWithCalibratedRed:rFloat green:gFloat blue:bFloat alpha:1.0];
.point
ws.layer.borderColor = NSColorFromName(BoardFrameColor).CGColor;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
2016-12-06 六.(二)oc分类-category(范畴、非正式协议)
2016-12-06 十二 .ocBlock
2016-12-06 十.oc内存管理
2016-12-06 七.(一)oc通知-NSNotification(通知中心-NSNotificationCenter)