2
我試圖讓我的UITableViewCell的字體大小變小。這裏是我的代碼:UITableViewCell字體大小不變
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* CellIdentifier = @"Cell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
UILabel *nameLabel;
UISwitch *mySwitch;
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault
reuseIdentifier: CellIdentifier] autorelease];
nameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(220, 13, 100, 20)] autorelease];
nameLabel.tag = 22;
nameLabel.font = [UIFont boldSystemFontOfSize: 5.0];
nameLabel.textColor = [UIColor blueColor];
nameLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
nameLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview: nameLabel];
mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
mySwitch.tag = ((400*(indexPath.section+1))+indexPath.row);
[mySwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
[cell addSubview:mySwitch];
cell.accessoryView = mySwitch;
}
else {
nameLabel = (UILabel*)[cell.contentView viewWithTag: 22];
mySwitch = (UISwitch *)[cell.contentView viewWithTag:((400*(indexPath.section+1))+indexPath.row)];
}
nameLabel.textLabel.text = @"Hello";
}
但標籤的字體肯定是不出來是大小5.這是正常的字體和大小正常,大概是12號字體,或任何默認爲。爲什麼我無法更改字體大小?
有沒有您要添加的nameLabel到該單元的內容查看兩次理由嗎? – 2011-01-12 15:39:47