iPhone开发笔记

    1. 计算string串的像素长度:
      1 CGSize polLabelSize = [polName sizeWithFont:[UIFont boldSystemFontOfSize:16] constrainedToSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
      2 CGSize podLabelSize = [podName sizeWithFont:[UIFont boldSystemFontOfSize:16] constrainedToSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
      3 float polLabelWidth = (polLabelSize.width <= 125) ? polLabelSize.width : 125;
      4 float podLabelWidth = (podLabelSize.width <= 125) ? podLabelSize.width : 125;
      5 [polLabel setFrame:CGRectMake(10, 0, polLabelWidth, 32)];
      6 [pageHeaderArrow setFrame:CGRectMake(polLabelWidth + 20, 7, 30, 20)];
      7 [podLabel setFrame:CGRectMake(polLabelWidth + 60, 0, podLabelWidth, 32)];
      利用这个函数可以根据String的像素长度来确定lable或者其他控件的width 和 height,从而实现lable的灵活定位.
    2. 使用图片设置View的背景
      1 [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]]];
      2 [self.table setBackgroundColor:[UIColor clearColor]];
      tableView默认是白色背景,如果要tableView的背景和底层View的背景颜色一致,需要将tableView的bgc Clear一下.
    3. 读取自定义的Cell的方法
      1 static NSString *CellIdentifier = @"Cell";
      2 HistoricalReliablityViewCellStyle *cell = (HistoricalReliablityViewCellStyle *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      3 if(cell == nil)
      4 {
      5 NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"HistoricalReliablityViewCellStyle" owner:self options:nil];
      6 cell = [nib objectAtIndex:0];
      7 cell.selectionStyle = UITableViewCellSelectionStyleNone;
      8 }
      首先定义相应Cell的一个标识符(如@"Cell"),这是一个静态字符串. 然后符合苹果reuse的特点,先在用对应标识符标记的Cell重用queue里面查找是否有可重用的Cell,有就返回相应的Cell,否则返回nil.这时就需要为这种标识符标记的Cell创建一个Cell实例.上面这个例子是从Cell的xib文件中读取构建相应的Cell.
    4. 获取屏幕的边界
      CGRect screenBounds = [[UIScreen mainScreen]bounds];
      CGRect screenBounds = [[UIScreen mainScreen]applicationFrame];
      bounds方法会返回整个屏幕的边界,包括状态栏所占用的控件;而applicationFrame方法则返回屏幕的可显示区域,不包括状态栏.
原文地址:https://www.cnblogs.com/woainilsr/p/2355317.html