UIButton *informationCardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[informationCardBtn addTarget:self action:@selector(enterehzFilesVC:) forControlEvents:UIControlEventTouchUpInside];
[informationCardBtn setImage:[UIImage imageNamed:@"个人_未点击"] forState:UIControlStateNormal];
[informationCardBtn sizeToFit];
UIBarButtonItem *informationCardItem = [[UIBarButtonItem alloc] initWithCustomView:informationCardBtn];
UIBarButtonItem *fixedSpaceBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedSpaceBarButtonItem.width = 22;
UIButton *settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[settingBtn addTarget:self action:@selector(enterTeamCard:) forControlEvents:UIControlEventTouchUpInside];
[settingBtn setImage:[UIImage imageNamed:@"商家_未点击"] forState:UIControlStateNormal];
[settingBtn sizeToFit];
UIBarButtonItem *settingBtnItem = [[UIBarButtonItem alloc] initWithCustomView:settingBtn];
self.navigationItem.rightBarButtonItems = @[informationCardItem,fixedSpaceBarButtonItem,settingBtnItem];
UIButton *detailButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
[detailButton setImage:[UIImage imageNamed:@"group_detail"] forState:UIControlStateNormal];
[detailButton addTarget:self action:@selector(showGroupDetailAction) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:detailButton];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithTitle:@"退出" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemPressed:)];
[self.navigationItem setLeftBarButtonItem:leftButton];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
});
});
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];//str->data
NSDictionary *rootDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSLog(@"NSJSONSerialization=%@", rootDic);
__weak typeof(self)weakSelf = self;
日期转换为时间戳 (日期转换为秒数)
NSDate *date = [NSDate date];
NSLog(@"当前日期为:%@",date);
NSTimeInterval timeStamp= [date timeIntervalSince1970];
NSLog(@"日期转换为时间戳 %@ = %f", date, timeStamp);
时间戳转日期 (秒数转日期)
NSString *timeStamp2 = @"1414956901";
long long int date1 = (long long int)[timeStamp2 intValue];
NSDate *date2 = [NSDate dateWithTimeIntervalSince1970:date1];
NSLog(@"时间戳转日期 %@ = %@", timeStamp2, date2)
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);
if (!_isPhotoChat) {
// 假设偏移表格高度的20%进行刷新
if (!_isLoading) { // 判断是否处于刷新状态,刷新中就不执行
// 取内容的高度:
// 如果内容高度大于UITableView高度,就取TableView高度
// 如果内容高度小于UITableView高度,就取内容的实际高度
float height = scrollView.contentSize.height > self.chatTableView.frame.size.height ? self.chatTableView.frame.size.height : scrollView.contentSize.height;
if ((height - scrollView.contentSize.height + scrollView.contentOffset.y) / height > 0.2) {
// 调用上拉刷新方法
NSLog(@"调用上拉刷新方法");
}
if (- scrollView.contentOffset.y / self.chatTableView.frame.size.height > 0.2) {
// 调用下拉刷新方法
NSLog(@"调用下拉刷新方法");
_isLoading = YES;
[self loadData2];
}
}
}
- //给图层添加背景图片:
- //myView.layer.contents = (id)[UIImage imageNamed:@"view_BG.png"].CGImage;
- //将图层的边框设置为圆脚
- myWebView.layer.cornerRadius = 8;
- myWebView.layer.masksToBounds = YES;
- //给图层添加一个有色边框
- myWebView.layer.borderWidth = 5;
- myWebView.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:1] CGColor];
今天记录下 UILabel的高度和宽度自适应,方法特别简单
1 创建category
.h中
+ (CGFloat)getHeightByWidth:(CGFloat)width title:(NSString *)title font:(UIFont*)font;
+ (CGFloat)getWidthWithTitle:(NSString *)title font:(UIFont *)font;
.m中
+ (CGFloat)getHeightByWidth:(CGFloat)width title:(NSString *)title font:(UIFont *)font
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
label.text = title;
label.font = font;
label.numberOfLines = 0;
[label sizeToFit];
CGFloat height = label.frame.size.height;
return height;
}
+ (CGFloat)getWidthWithTitle:(NSString *)title font:(UIFont *)font {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1000, 0)];
label.text = title;
label.font = font;
[label sizeToFit];
return label.frame.size.width;
}