for (UIView *view in headerView.subviews) { [view removeFromSuperview]; }
[view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
- (UINavigationController*)viewController { for (UIView* next = [self superview]; next; next = next.superview) { UIResponder* nextResponder = [next nextResponder]; if ([nextResponder isKindOfClass:[UINavigationController class]]) { return (UINavigationController*)nextResponder; } } return nil; } - (UIViewController*)viewControllerSelf{ for (UIView* next = [self superview]; next; next = next.superview) { UIResponder* nextResponder = [next nextResponder]; if ([nextResponder isKindOfClass:[UINavigationController class]]) { return (UIViewController*)nextResponder; } } return nil; }
代码以下:html
- (void)setNavigationBar { // 建立NavigationBar UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, ScreeFrame.size.width, 64)]; navigationBar.backgroundColor = [UIColor whiteColor]; // 添加按钮 (左右都可 例子为左侧返回按钮) UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom]; backButton.frame = CGRectMake(0, 0, ScreeFrame.size.width / 6, 40); backButton.titleLabel.font = [UIFont systemFontOfSize:15]; [backButton setTitle:@"戻る" forState:UIControlStateNormal]; [backButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal]; // 添加点击事件 [backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside]; // 建立 NavigationItem UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"分类"]; UIBarButtonItem *leftButtton = [[UIBarButtonItem alloc] initWithCustomView:backButton]; // 将自定义的按钮赋给Item的左侧按钮 item.leftBarButtonItem = leftButtton; // 显示NavigationBar [navigationBar pushNavigationItem:item animated:YES]; [self addSubview:navigationBar]; }
iOS7之前:程序员
navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor orangeColor] forKey:UITextAttributeTextColor];
iOS7之后:设计模式
navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor orangeColor] forKey:NSForegroundColorAttributeName];
iOS7以后:设置Title颜色及字体大小,都须要用到:NSForegroundColorAttributeName数组
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, [UIFont systemFontOfSize:14], NSForegroundColorAttributeName, nil]];
注:app
屡次打印检测出以下方法返回的数组元素个数为3(是由于这个方法是 Visible 显示在屏幕上可见的视图 )ide
// 返回值是NSIndexPath的数组 [self.collectionView_Subject indexPathsForVisibleSupplementaryElementsOfKind:UICollectionElementKindSectionHeader]
本部份内容原博:http://blog.it985.com/8776.html函数
时间转换为时间戳:字体
NSDate *date = [NSDate date]; NSLog(@"当前日期为:%@",date); NSTimeInterval timeStamp= [date timeIntervalSince1970]; NSLog(@"日期转换为时间戳 %@ = %f", date, timeStamp);
时间戳转换为时间:spa
NSString *timeStamp2 = @"1414956901"; long long int date1 = (long long int)[timeStamp2 intValue]; NSDate *date2 = [NSDate dateWithTimeIntervalSince1970:date1]; NSLog(@"时间戳转日期 %@ = %@", timeStamp2, date2);
获取当前时间:.net
NSDate *currentDate = [NSDate date];//获取当前时间,日期 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"YYYY/MM/dd hh:mm:ss SS"]; NSString *dateString = [dateFormatter stringFromDate:currentDate]; NSLog(@"dateString:%@",dateString);
NSEnumerator *enumerator=[self.segment.subviews reverseObjectEnumerator];//获得集合的倒序迭代器 id obj = nil; NSInteger i = 0; while(obj = [enumerator nextObject]){ if (i < count - 3 ) { [self.segment.subviews[i] removeFromSuperview]; // NSLog(@"BBB %ld", self.segment.subviews.count); } i++; }
button.selected 默认为NO
button或者imageView设置图片圆角:在Xcode7以上:(强调clipsToBounds这个属性)
// 这个属性只是习惯加上去了 不知道去了可不能够设置圆角(不加也能够的 ~ ) [detailButton layoutIfNeeded]; // 这个属性很重要 设置以后才能变成圆角 detailButton.clipsToBounds = YES; detailButton.layer.cornerRadius = detailButton.frame.size.width / 8;
原博:http://blog.csdn.net/leikezhu1981/article/details/7446001
http://blog.csdn.net/chengyingzhilian/article/details/7930398
默认值为YES。
automaticallyAdjustsScrollViewInsets根据按所在界面的status bar,navigationbar,与tabbar的高度,自动调整scrollview的 inset,通常状况下须要程序员手动设置为NO, 不让viewController 调整。[button setImage:[[UIImage imageNamed:@"2.jpeg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
imageWithRenderingMode:,它使用UIImageRenderingMode枚举值来设置图片的renderingMode属性。该枚举中包含下列值:
UITableViewCell *cell = (UITableViewCell *)sender.superview.superview;
NSIndexPath *index = [self.tableView_Follow indexPathForCell:cell];
计算UILabel文字高度的时候,
使用方法:- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(nullable NSDictionary<NSString *, id> *)attributes context:(nullable NSStringDrawingContext *)context实现
NSStringDrawingOptions:若是是在多行的状况下,至少要包括:NSStringDrawingUsesLineFragmentOrigin、NSStringDrawingUsesFontLeading
- (CGSize)labelAutoWithText:(NSString *)text FontSize:(NSInteger)fontSize MaxSize:(CGSize)maxSize{ NSDictionary *dic = @{ NSFontAttributeName:[UIFont systemFontOfSize:14]//字号的名字 }; return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading | NSStringDrawingTruncatesLastVisibleLine attributes:dic context:nil].size; }
原博地址:http://my.oschina.net/caijunrong/blog/510701
Key Value Observing, 顾名思义就是一种observer 模式用于监听property的变化,KVO跟NSNotification有不少类似的地方, 用addObserver:forKeyPath:options:context:去start observer, 用removeObserver:forKeyPath:context去stop observer, 回调就是observeValueForKeyPath:ofObject:change:context:。
KVO 的实现也依赖于 Objective-C 强大的 Runtime 。
1> 将系统NavigationBar上的返回按钮的文字去掉(文字是前一个控制器的title) 只留下箭头
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-500, 0) forBarMetrics:UIBarMetricsDefault];
2> 给backBarButtonItem设置图片:
// 返回按钮 UIImage *img = [UIImage imageNamed:@"back"]; img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; self.navigationController.navigationBar.backIndicatorImage = img; self.navigationController.navigationBar.backIndicatorTransitionMaskImage = img; self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; // 将后面的文字偏移,进行隐藏 [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-500, 0) forBarMetrics:UIBarMetricsDefault];
barTintColor:bar的背景色
TintColor:按钮的颜色
。。