UIView設(shè)置半透明后不影響其上子控件透明度的方法
self.view.backgroundColor= [[UIColor grayColor] colorWithAlphaComponent:0.5];
通過這種方法設(shè)置透明度不會(huì)影響加載在其上的控件的透明度
通過?indexPath 獲取?Cell
UITableViewCell?*cell = [tableView cellForRowAtIndexPath:indexPath];
包含字符串
[str1 containsString:str2]
iOS 字符串的操作,去掉某一個(gè)字符或者替換成其他字符
NSString *strUrl = [urlString stringByReplacingOccurrencesOfString:@" " withString:@""]; ?去掉空格
NSString *strUrl = [urlString stringByReplacingOccurrencesOfString:@" " withString:@"/"];替換字符
iOS設(shè)置UIButton文字顯示位置和字體大小、顏色的方法
設(shè)置按鈕上的自體的大小
[btn setFont: [UIFont systemFontSize: 14.0]]; //這種可以用來設(shè)置字體的大小,但是可能會(huì)在將來的SDK版本中去除改方法
應(yīng)該使用btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
UIButton的title居左對(duì)齊?
btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;
此時(shí)文字會(huì)緊貼到做邊框,我們可以設(shè)置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);//使文字距離做邊框保持10個(gè)像素的距離。
UIButton字體顏色
[btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
UITableView
去掉Cell下劃線
tableView.separatorStyle =UITableViewCellSeparatorStyleNone;//推薦該方法
取消headerView懸停
tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
超出隱藏
cell.layer.masksToBounds = YES;
刪除所有子視圖
?[cell.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
UIButton 按鈕邊框
[box.actionButton.layer setMasksToBounds:YES]; [box.actionButton.layer setCornerRadius:10.0];//設(shè)置矩形四個(gè)圓角半徑? [box.actionButton.layer setBorderWidth:1.0];//邊框?qū)挾?
//設(shè)置邊框顏色有兩種方法:
第一種如下:
?CGColorSpaceRefcolorSpace =CGColorSpaceCreateDeviceRGB();
CGColorRefcolorref =CGColorCreate(colorSpace,(CGFloat[]){0,0,0,1});?
?[box.actionButton.layer setBorderColor:colorref];//邊框顏色?
?//第二種方法如下:
?//button.layer.borderColor=[UIColor grayColor].CGColor;
UILabel 換行
@property(nonatomic)??????? NSLineBreakMode??? lineBreakMode;?
?? UILineBreakModeWordWrap = 0,?以單詞為單位換行,以單位為單位截?cái)唷?/p>
?? UILineBreakModeCharacterWrap,??? 以字符為單位換行,以字符為單位截?cái)唷?
?? UILineBreakModeClip,?以單詞為單位換行。以字符為單位截?cái)唷?/p>
? ?UILineBreakModeTailTruncation,?以單詞為單位換行。無(wú)論是單行還是多行,都是末尾有省略號(hào)。
? ?UILineBreakModeMiddleTruncation,?以單詞為單位換行。無(wú)論是單行還是多行,都是中間有省略號(hào),省略號(hào)后面只有2個(gè)字符。?
?? UILineBreakModeHeadTruncation,??以單詞為單位換行。如果是單行,則開始部分有省略號(hào)。如果是多行,則中間有省略號(hào),省略號(hào)后面有4個(gè)字符。
label 中劃線
UILabel*strikeLabel=[[UILabel alloc]initWithFrame:(CGRectMake(10,10,50,30))];NSString*textStr=[NSString stringWithFormat:@"%@元",primeCost];//中劃線NSDictionary*attribtDic=@{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]};NSMutableAttributedString*attribtStr=[[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];// 賦值strikeLabel.attributedText=attribtStr;[self.view addSubview:strikeLabel];
label 下劃線
UILabel*underlineLabel=[[UILabel alloc]initWithFrame:(CGRectMake(10,10,50,30))];NSString*textStr=[NSString stringWithFormat:@"%@元",primeCost];// 下劃線NSDictionary*attribtDic=@{NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]};NSMutableAttributedString*attribtStr=[[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];//賦值underlineLabel.attributedText=attribtStr;[self.view addSubview:underlineLabel];
// 1. 創(chuàng)建一個(gè)點(diǎn)擊事件,點(diǎn)擊時(shí)觸發(fā)labelClick方法
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popRenzhengView)];
// 2. 將點(diǎn)擊事件添加到label上
[cell.goRZLabel addGestureRecognizer:gesture];
//開啟用戶交互
cell.goRZLabel.userInteractionEnabled = YES;
獲取狀態(tài)欄高度
-(float)mStatusbarHeight{
? ? //狀態(tài)欄高度
? ? return [[UIApplication sharedApplication] statusBarFrame].size.height;
}
獲取導(dǎo)航欄高度+狀態(tài)欄高度
-(float)mNavigationbarHeight{
? ? //導(dǎo)航欄高度+狀態(tài)欄高度
? ? return self.navigationController.navigationBar.frame.size.height + [[UIApplication sharedApplication] statusBarFrame].size.height;
}
獲取Tabbar高度
-(float)mTabbarHeight{
? ? //Tabbar高度
? ? return self.tabBarController.tabBar.bounds.size.height;
}
? ?從導(dǎo)航堆棧中刪除 viewcontrollers
替換
? ? NSArray *arr = self.navigationController.viewControllers;
? ? NSArray*navNewArr = [[NSArrayalloc]initWithObjects:arr[0],arr[1],arr[2],arr[4],nil];
? ? self.navigationController.viewControllers = navNewArr;
刪除
NSMutableArray *navigationarray = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[navigationarray removeObjectAtIndex:4];
[navigationarray removeObjectAtIndex:3];
self.navigationController.viewControllers = navigationarray;
iOS13 狀態(tài)欄
UIView*statusBar;
? ? if(@available(iOS13.0, *)) {
? ? ? ? UIWindow*keyWindow = [UIApplicationsharedApplication].keyWindow;
? ? ? ? UIView*viewStatusColorBlend = [[UIViewalloc]initWithFrame:keyWindow.windowScene.statusBarManager.statusBarFrame];
? ? ? ? viewStatusColorBlend.backgroundColor= color;
? ? ? ? [keyWindowaddSubview:viewStatusColorBlend];
? ? }else{
? ? ? ? statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
? ? ? ? if([statusBarrespondsToSelector:@selector(setBackgroundColor:)]) {
? ? ? ? ? ? statusBar.backgroundColor= color;
? ? ? ? }
? ? }