您的位置:首页 > 其它

iPhone开发笔记

2012-02-17 09:57 239 查看
计算string串的像素长度:

CGSize polLabelSize = [polName sizeWithFont:[UIFont boldSystemFontOfSize:16] constrainedToSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
CGSize podLabelSize = [podName sizeWithFont:[UIFont boldSystemFontOfSize:16] constrainedToSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
float polLabelWidth = (polLabelSize.width <= 125) ? polLabelSize.width : 125;
float podLabelWidth = (podLabelSize.width <= 125) ? podLabelSize.width : 125;
[polLabel setFrame:CGRectMake(10, 0, polLabelWidth, 32)];
[pageHeaderArrow setFrame:CGRectMake(polLabelWidth + 20, 7, 30, 20)];
[podLabel setFrame:CGRectMake(polLabelWidth + 60, 0, podLabelWidth, 32)];


利用这个函数可以根据String的像素长度来确定lable或者其他控件的width 和 height,从而实现lable的灵活定位.

使用图片设置View的背景

[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]]];
[self.table setBackgroundColor:[UIColor clearColor]];


tableView默认是白色背景,如果要tableView的背景和底层View的背景颜色一致,需要将tableView的bgc Clear一下.

读取自定义的Cell的方法

static NSString *CellIdentifier = @"Cell";
HistoricalReliablityViewCellStyle *cell = (HistoricalReliablityViewCellStyle *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"HistoricalReliablityViewCellStyle" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}


首先定义相应Cell的一个标识符(如@"Cell"),这是一个静态字符串. 然后符合苹果reuse的特点,先在用对应标识符标记的Cell重用queue里面查找是否有可重用的Cell,有就返回相应的Cell,否则返回nil.这时就需要为这种标识符标记的Cell创建一个Cell实例.上面这个例子是从Cell的xib文件中读取构建相应的Cell.

获取屏幕的边界

CGRect screenBounds = [[UIScreen mainScreen]bounds];
CGRect screenBounds = [[UIScreen mainScreen]applicationFrame];


bounds方法会返回整个屏幕的边界,包括状态栏所占用的控件;而applicationFrame方法则返回屏幕的可显示区域,不包括状态栏.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: