iOS中tableViewCell文字居中显示

来源:互联网 发布:丙烯酸和js哪个好 编辑:程序博客网 时间:2024/05/23 20:16
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{        static NSString *indentify = @"ReportCell";        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentify];    if (cell == nil) {                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentify];    }    cell.selectionStyle = UITableViewCellSelectionStyleNone;    cell.textLabel.textAlignment = NSTextAlignmentCenter;//文字居中    cell.textLabel.text = @"广告";    return cell;}

tableView单元格居中显示:

cell.textLabel.textAlignment =NSTextAlignmentCenter;//文字居中

注意:cell的类型需要是 UITableViewCellStyleDefault。

类型如下:

typedef NS_ENUM(NSInteger, UITableViewCellStyle) {

    UITableViewCellStyleDefault,// Simple cell with text label and optional image view (behavior of UITableViewCell in iPhoneOS 2.x)

    UITableViewCellStyleValue1,// Left aligned label on left and right aligned label on right with blue text (Used in Settings)

    UITableViewCellStyleValue2,// Right aligned label on left with blue text and left aligned label on right (Used in Phone/Contacts)

    UITableViewCellStyleSubtitle// Left aligned label on top and left aligned label on bottom with gray text (Used in iPod).

};             // available in iPhone OS 3.0



0 0
原创粉丝点击