首页 > iOS小知识点记录

iOS小知识点记录

1>UITextField实现leftView:

self.inputTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, 10, 200, 25)];self.inputTextField.delegate = self;self.inputTextField.font = [UIFont systemFontOfSize:15];self.inputTextField.placeholder = @" 想说点什么?";// 设置textField显示图标UIView *placeHolderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 30)];UIImageView *icon = [[UIImageView alloc]initWithFrame:CGRectMake(5, 7, 15, 15)];icon.backgroundColor = [UIColor redColor]; // 这里我只是设置了颜色,你改成图片就行[placeHolderView addSubview:icon];self.inputTextField.leftView = placeHolderView;self.inputTextField.leftViewMode = UITextFieldViewModeAlways;self.inputTextField.backgroundColor = [UIColor whiteColor];[self addSubview:_inputTextField];

注意一定要设置:     self.inputTextField.leftViewMode = UITextFieldViewModeAlways;  否则不会显示的哟...

2>有时候程序运行崩溃,是因为全局断点造成的哟...

3>设置Xib画的label顶部对齐:

参考链接: http://blog.csdn.net/u013316626/article/details/71059601

 

- (void)drawRect:(CGRect)rect {[super drawRect:rect];[self.contentLabel sizeToFit];
} 

 

4>整体框架搭建基本设置:

效果图:

 

 

 

NavigationController:

+ (void)initialize {UINavigationBar *bar = [UINavigationBar appearance];[bar setBarTintColor:[UIColor whiteColor]];NSMutableDictionary *attrs = [NSMutableDictionary dictionary];attrs[NSFontAttributeName] = [UIFont systemFontOfSize:16];attrs[NSForegroundColorAttributeName] = [UIColor blackColor];[bar setTitleTextAttributes:attrs];
}- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {if (self.childViewControllers.count > 0) {UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];[button setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];button.size = CGSizeMake(30, 30);[button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];// 隐藏tabbarviewController.hidesBottomBarWhenPushed = YES;}[super pushViewController:viewController animated:animated];
}- (void)back {[self popViewControllerAnimated:YES];
}

TabBarController:

#pragma mark - 统一设置所有 UITabBarItem 的文字属性
+ (void)initialize {NSMutableDictionary *attrs = [NSMutableDictionary dictionary];attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];attrs[NSForegroundColorAttributeName] = [UIColor grayColor];NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];selectedAttrs[NSForegroundColorAttributeName] = [UIColor colorWithRed:255/255.0 green:125/255.0 blue:0 alpha:1];UITabBarItem *items = [UITabBarItem appearance];[items setTitleTextAttributes:attrs forState:UIControlStateNormal];[items setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
}#pragma mark - 初始化
- (instancetype)init {if (self = [super init]) {[self addChildViewControllers];[self addComposeButton];}return self;
}#pragma mark - 添加所有子控制器
- (void)addChildViewControllers {[self addChildViewControllerClassName:@"NNHomePageController" title:@"首页" imageName:@"tabbar_home"];[self addChildViewControllerClassName:@"NNFoundController" title:@"发现" imageName:@"tabbar_discover"];[self addChildViewController: [[UIViewController alloc] init]];[self addChildViewControllerClassName:@"NNMessageController" title:@"消息" imageName:@"tabbar_message_center"];[self addChildViewControllerClassName:@"NNMyController" title:@"我的" imageName:@"tabbar_profile"];
}#pragma mark - 设置所有子控制器
- (void)addChildViewControllerClassName:(NSString *)className title:(NSString *)title imageName:(NSString *)imageName
{UIViewController *viewController = [[NSClassFromString(className) alloc] init];NNNavigationController *nav = [[NNNavigationController alloc] initWithRootViewController:viewController];viewController.title = title;viewController.view.backgroundColor = [UIColor whiteColor];viewController.tabBarItem.image = [UIImage imageNamed: imageName];viewController.tabBarItem.selectedImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted", imageName]];[self addChildViewController:nav];
}#pragma mark - 添加中间的按钮
- (void)addComposeButton {UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];[button setImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];[button setImage:[UIImage imageNamed:@"tabBar_publish_icon_highlighted"] forState:UIControlStateSelected];[button addTarget:self action:@selector(composeButtonClick:) forControlEvents:UIControlEventTouchUpInside];self.composeButton = button;[self.tabBar addSubview:button];[self.tabBar bringSubviewToFront:button];CGFloat width = self.tabBar.bounds.size.width / self.childViewControllers.count - 2;self.tabBar.tintColor = [UIColor colorWithRed:68/255.0 green:173/255.0 blue:159/255.0 alpha:1];button.frame = CGRectInset(self.tabBar.bounds, 2 * width, 0);
}#pragma mark - 点击写文章按钮
- (void)composeButtonClick:(UIButton *)button {NSLog(@"
点击了写文章按钮");AddViewController *addVc = [AddViewController new];NNNavigationController *nav = [[NNNavigationController alloc]initWithRootViewController:addVc];[self presentViewController: nav animated:YES completion:nil];
}- (void)viewWillAppear:(BOOL)animated {[super viewWillAppear:animated];[self.tabBar bringSubviewToFront:self.composeButton];
}

 

转载于:https://www.cnblogs.com/pengsi/p/7305893.html

更多相关:

  • class str(basestring):"""str(object='') -> stringReturn a nice string representation of the object.If the argument is a string, the return value is the same object."""d...

  • 目录结构: contents structure [-] 类的基本使用专有方法继承单重继承多重继承砖石继承 1.类的基本使用 下面是类使用的一个简单案例, class person:"person 类的描述信息"def __init__(self,name="",age=0):self.name = nameself.age =...

  • 一、反射 反射的概念是由Smith在1982年首次提出的,主要是指程序可以访问、检测和修改它本身状态或行为的一种能力(自省)。这一概念的提出很快引发了计算机科学领域关于应用反射性的研究。它首先被程序语言的设计领域所采用,并在Lisp和面向对象方面取得了成绩。 python面向对象中的反射:通过字符串的形式操作对象相关的属性。pytho...

  • 一、set集合的方法 set不是特别常用,但是set的一些特性可以方便处理一些特殊情况。 集合(set)是一个无序不重复元素的序列。 可以使用大括号 { } 或者 set() 函数创建集合,注意:创建一个空集合必须用 set() 而不是 { },因为 { } 是用来创建一个空字典。 创建格式: parame = {value01,va...

  • app.component.html

  • 点击图片放大看效果 上代码

    WPF布局(2) 使用的DockPanel面板进行简单的布局

    DockPanel 面板是根据外边缘进行控件的拉伸,DockPanel的LastChildFill属性设置为True 时,最后一个添加的控件将占满剩余空间。  

  • 1 2 3 4 5 JS实现幻动片选项卡 6 7