隐藏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;
}