隱藏tableViewCell的分割線
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
實現右側的小灰色箭頭 > 只要將cell的accessoryType屬性設置為
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
關閉tableView頂部的cell冒出來的白色空隙
self.automaticallyAdjustsScrollViewInsets = NO
關閉tableView選中的動畫
[tableView deselectRowAtIndexPath:indexPath animated:NO];
開啟手勢返回
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
用UiButton制作圓形頭像時,去除頭像多余的部分
button.clipsToBounds = YES;
毛玻璃效果(ios8.0以后的版本)
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
visualEffectView.frame = CGRectMake(0, 0, 320, 180);
visualEffectView.alpha = 1.0;
關閉textField、textView 相關
//是否自動糾錯功能
text.autocorrectionType = UITextAutocorrectionTypeNo;
typedef enum {
UITextAutocorrectionTypeDefault, 默認
UITextAutocorrectionTypeNo, 不自動糾錯
UITextAutocorrectionTypeYes, 自動糾錯
} UITextAutocorrectionType;
每輸入一個字符就變成點 用語密碼輸入
text.secureTextEntry = YES;
textField輸入框出現刪除按鈕
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
layoutSubviews什么時候調用
在init初始化時不會調用layouSubviews,使用initWithFrame時候,只要rect值不為zero會調用layouSubviews。
addSubview時會觸發layouSubviews
設置view的frame時,只要view的值有變化,則會調用layouSubviews
滾動UIScrollView會調用layouSubviews
旋轉當前APP會調用layouSubviews
更改一個View的大小的時,也會觸發父類的layouSubviews
導航欄全透明,無黑邊
// 導航欄變為透明
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:0];
// 讓黑線消失的方法
self.navigationController.navigationBar.shadowImage = [UIImage new];
解決ios11的頂部20px問題
if (@available(iOS 11.0, *)) {
UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
// Fallback on earlier versions
}
取消/顯示導航欄的黑線
//顯示導航欄黑線
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
//隱藏導航欄黑線
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
時間狀態欄的顏色
-(UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
//在MainTabbarController里,例如
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (CGColorEqualToColor(NAVColor.CGColor, navigationController.navigationBar.barTintColor.CGColor)) {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];//白色
} else {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];//黑色
}
}
改變當前的視圖控制器
self.view.window.rootViewController = [[MainTabbarViewController alloc] init];
枚舉
typedef NS_ENUM(NSInteger, CellTwoType) {
ForLendMoenyPersionInfo,
ForSafeguard
};
@property(nonatomic, assign) CellTwoType cellTwoType;
在使用view的縮放的時候,layer.border.width隨著view的放大,會出現鋸齒化的問題,解決這個問題需要設置這個屬性
self.layer.allowsEdgeAntialiasing = YES;
自定義了leftBarbuttonItem左滑返回手勢失效了怎么辦?
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:img
style:UIBarButtonItemStylePlain
target:self
action:@selector(onBack:)];
self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
點擊全局收起鍵盤
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
導航條返回鍵帶的title太討厭了,怎么讓它消失?
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
labe行間距/計算行間距情況下高度
#define UILABEL_LINE_SPACE 4
//Label行間距等
+ (void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font {
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
paraStyle.alignment = NSTextAlignmentLeft;
paraStyle.lineSpacing = UILABEL_LINE_SPACE; //設置行間距
paraStyle.hyphenationFactor = 1.0;
paraStyle.firstLineHeadIndent = 0.0;
paraStyle.paragraphSpacingBefore = 0.0;
paraStyle.headIndent = 0;
paraStyle.tailIndent = 0;
//設置字間距 NSKernAttributeName:@1.5f
NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f
};
NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];
label.attributedText = attributeStr;
}
//計算UILabel的高度(帶有行間距的情況)
+ (CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(UIFont*)font withWidth:(CGFloat)width {
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
paraStyle.alignment = NSTextAlignmentLeft;
paraStyle.lineSpacing = UILABEL_LINE_SPACE;
paraStyle.hyphenationFactor = 1.0;
paraStyle.firstLineHeadIndent = 0.0;
paraStyle.paragraphSpacingBefore = 0.0;
paraStyle.headIndent = 0;
paraStyle.tailIndent = 0;
NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f
};
CGSize size = [str boundingRectWithSize:CGSizeMake(width, HEIGHT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
return size.height;
}
如果簡單項目nav作為主控制器
"AppDelegate.m"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController *vc = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
nav.navigationBar.translucent = YES;
nav.navigationBar.barTintColor = kNavColor;
[nav.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:kTextColor, NSFontAttributeName:[UIFont fontWithName:@"Helvetica-Bold" size:19]}];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}