iOS -小知识集

2020-08-05  本文已影响0人  善良的皮蛋

知识小集目录



_bottomView.backgroundColor = [[UIColor akext_colorWithHex:@"#0437F1"] colorWithAlphaComponent:0.5];
 _bgView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
if (@available(iOS 11.0, *)) {
    _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
    // Fallback on earlier versions
    self.automaticallyAdjustsScrollViewInsets = NO;
}

[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:indexPath.item inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
substringFromIndex:从Index开始截取到最后

substringToIndex:从最前头一直截取到Index
  NSString *fileName = [[NSBundle mainBundle] pathForResource:@"StoreInfoDat" ofType:@"geojson"];
    //check file exists
    if (fileName) {
      //retrieve file content
      NSData *partyData = [[NSData alloc] initWithContentsOfFile:fileName];

      //convert JSON NSData to a usable NSDictionary
      NSError *error;
      NSDictionary *party = [NSJSONSerialization JSONObjectWithData:partyData
        options:0
          error:&error];
      if (error) {
        NSLog(@"Something went wrong! %@", error.localizedDescription);
      }
      else {
        NSLog(@"party info: %@", party);
      }
    }
   else {
      NSLog(@"Couldn't find file!\n\n");
    }
 #if TARGET_IPHONE_SIMULATOR//模拟器
    #elif TARGET_OS_IPHONE//真机
    #endif

待续...

导入SDWebImage库文件
在应用的文件中添加#import <SDWebImage/UIButton+WebCache.h>头文件

[btn.imageView sd_setImageWithURL:[NSURL URLWithString:@"按钮url地址"] placeholderImage:[UIImage imageNamed:@"占位图片"]];
   /** 放置tableview 不停的刷新 */
        _baseTableView.estimatedRowHeight = 0;
        _baseTableView.estimatedSectionHeaderHeight = 0;
        _baseTableView.estimatedSectionFooterHeight = 0;

最关键的是:按钮要添加到cell的contentview上。否则点击不会生效。

if (@available(iOS 11.0, *)) {
    NSLog(@"iOS 11以上版本");
} else {
    NSLog(@"iOS 11以下版本");
}
下面两个代码的运行,你就会发现区别了。

//结果为0.468
CGFloat tFloat = (CGFloat)375/800;
//结果为0
CGFloat tFloat = 375/800;
//结果为0
CGFloat tFloat = 1/0;
//结果为+lnf 代表正无穷
CGFloat tFloat = (CGFloat)1/0;
原因:两个整数相除,结果也为整数
//        //插入的位置
//        NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(1, array.count)];
//        [self.dataArray insertObjects:array atIndexes:indexSet];
[self.dataArray insertObject:array atIndex:1];

一定要可变数组才行

//可变-不可变
NSArray *myArray = [NSArray arrayWithArray: myMutableArray];
//不可变-可变
self.dataArray = [NSMutableArray arrayWithArray:tempArray];
[self.baseCollectionView reloadItemsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:2], nil]];

1.将array数组转换为string字符串

 NSString *str = [array componentsJoinedByString:@"#"];//#为分隔符

输入:[str,kkk,jjj]
输出:str#kkk#jjj

2.将string字符串拆分为array数组[有分割符]

NSArray *array = [str componentsSeparatedByString:@"#"];//#为分隔符

输入: str#kkk#jjj
输出: [str,kkk,jjj]

NSArray *array = [NSArray arrayWithObjects:@"Crystal",@"Maisie",@"Lukas",@"Ruben",@"Brooklynn",@"Melody",@"Imogen",@"Skye",@"Rafael",@"Lindsey",@"Felix",nil];
NSArray *topThree = [array subarrayWithRange:NSMakeRange(0, 3)];
NSArray *remaining = [array subarrayWithRange:NSMakeRange(3, array.count-3)];
NSLog(@"topThree:%@=======remaining:%@",topThree,remaining);

[self.storeNameLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
image.png
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
上一篇 下一篇

猜你喜欢

热点阅读