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(@"\n點擊了寫文章按鈕");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
總結
- 上一篇: ACM 竞赛高校联盟 练习赛 第二场
- 下一篇: 排序算法7---快速排序算法