禁止横屏旋转
一、禁止横屏旋转
1、#pragma mark - 禁止横屏
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
returnUIInterfaceOrientationMaskPortrait;
}
2、//自动旋转
- (BOOL)shouldAutorotate {
returnNO;
}
//支持的屏幕转向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
//使用 UIInterfaceOrientationPortrait横屏播放视频结束后,app依然横屏,而table回到竖屏,不与app保持一致
//return UIInterfaceOrientationPortrait;
//使用 UIInterfaceOrientationMaskPortrait横屏播放视频结束后,app与table一起回到竖屏,保持了一致
returnUIInterfaceOrientationMaskPortrait;
}
二、TabBarController
1、这个控制器是tableviewcontroller,当后续页面直接用pop返回root时,需要删除自带的tabbar
-(void)viewWillLayoutSubviews{
[superviewWillLayoutSubviews];
for (UIView *childinself.tabBarController.tabBar.subviews) {
if ([childisKindOfClass:NSClassFromString(@"UITabBarButton")]) {
[child removeFromSuperview];
}
}
}
for (UIView *childin self.tabBarController.tabBar.subviews) {
if ([childisKindOfClass:[UIControlclass]]) {
[child removeFromSuperview];
}
}
2、隐藏底部tabbar
//1.设置self.tabBarController.tabBar.hidden=YES; self.tabBarController.tabBar.hidden=YES;//2.如果在push跳转时需要隐藏tabBar,设置self.hidesBottomBarWhenPushed=YES;
三、NavigationController
1、设置导航条颜色
[self.navigationController.navigationBarsetBarTintColor:COLOR_S_WHITE];
2、设置给定控制状态标题的文本属性
[self.navigationController.navigationBarsetTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:COLOR_S_BLACK,NSForegroundColorAttributeName,nil]];
3、隐藏导航条
self.navigationController.navigationBarHidden =NO;
4、navigationBar的毛玻璃效果 。translucent设置为YES时,导航栏呈现半透明效果
iOS7之后由于navigationBar.translucent默认是YES,坐标零点默认在(0,0)点 当不透明的时候,零点坐标在(0,64);如果你想设置成透明的,而且还要零点从(0,64)开始,那就添加:self.edgesForExtendedLayout = UIRectEdgeNone;
self.navigationController.navigationBar.translucent = YES;
5、// 隐藏导航栏下方的分割线
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init]
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
四、TableView
1、table的滚动
self.tableView.scrollEnabled =NO; //设置tableview 不能滚动
2、table一键回到顶部
(1)[self.tableView setContentOffset:CGPointMake(0, 0) animated:YES]; (本人使用这个奏效)
(2)- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
(3)设置scrollsToTop = YES;这个属性,点击状态栏就可以返回顶部了。
3、设置cell不可编辑
table.allowsSelection =NO;
五、UIScrollView
1、设置导航栏下的空白位置是否自动下移
//根据状态栏、导航栏、底部栏自动调节导航栏以下空白是否下移
self.automaticallyAdjustsScrollViewInsets =NO;
六、UIButton
1、设置控件边框颜色以及宽度
btn.layer.borderColor = [UIColorredColor].CGColor;
btn.layer.borderWidth =1;
2.设置UIButton的文字显示位置、字体的大小、字体的颜色
//设置按钮上的自体的大小
//[btn setFont: [UIFont systemFontSize: 14.0]]; //这种可以用来设置字体的大小,但是可能会在将来的SDK版本中去除改方法
//应该使用
btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
tvnamelabel=[[UIButton alloc]initWithFrame:CGRectMake(5,5,200,40)];
这样初始化的button,文字默认颜色是白色的,所有如果背景也是白色的话,是看不到文字的,
btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft ;//设置文字位置,现设为居左,默认的是居中
有些时候我们想让UIButton的title居左对齐,我们设置
btn.textLabel.textAlignment = UITextAlignmentLeft
是没有作用的,我们需要设置
btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;
但是问题又出来,此时文字会紧贴到做边框,我们可以设置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
使文字距离做边框保持10个像素的距离。
设置UIButton上字体的颜色设置UIButton上字体的颜色,不是用:
[btn.titleLabel setTextColor:[UIColorblackColor]];
btn.titleLabel.textColor=[UIColor redColor];
而是用:
[btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
七、UILabel
1、根据label里的文字来自动适应尺寸
[labelsizeToFit];
2、根据label固定宽度来调节label的字体大小
adjustsFontSizeToFitWidth:文字内容自适应标签度,默认NO
label.adjustsFontSizeToFitWidth = YES;

浙公网安备 33010602011771号