iPhone开发笔记
- 计算string串的像素长度:
利用这个函数可以根据String的像素长度来确定lable或者其他控件的width 和 height,从而实现lable的灵活定位.
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)]; - 使用图片设置View的背景
tableView默认是白色背景,如果要tableView的背景和底层View的背景颜色一致,需要将tableView的bgc Clear一下.
1 [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]]];
2 [self.table setBackgroundColor:[UIColor clearColor]]; - 读取自定义的Cell的方法
首先定义相应Cell的一个标识符(如@"Cell"),这是一个静态字符串. 然后符合苹果reuse的特点,先在用对应标识符标记的Cell重用queue里面查找是否有可重用的Cell,有就返回相应的Cell,否则返回nil.这时就需要为这种标识符标记的Cell创建一个Cell实例.上面这个例子是从Cell的xib文件中读取构建相应的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 } - 获取屏幕的边界
bounds方法会返回整个屏幕的边界,包括状态栏所占用的控件;而applicationFrame方法则返回屏幕的可显示区域,不包括状态栏.
CGRect screenBounds = [[UIScreen mainScreen]bounds];
CGRect screenBounds = [[UIScreen mainScreen]applicationFrame];
- 计算string串的像素长度:

浙公网安备 33010602011771号