代码拉取完成,页面将自动刷新
UILabel subclass with vertical text alignment, insets, images and height calculation.
Specifically designed to use with UITableView.
To run the example project, clone the repo, and run pod install
from the Example directory first.
BTLabel *label = [[BTLabel alloc] initWithFrame:CGRectMake(10, 10, 300, 80) edgeInsets:UIEdgeInsetsMake(10, 20, 10, 10)];
label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
label.verticalAlignment = BTVerticalAlignmentCenter;
label.textAlignment = NSTextAlignmentLeft;
// in interface
@property (nonatomic, strong) NSArray *texts;
@property (nonatomic, strong) UIFont *font;
@property (nonatomic, assign) UIEdgeInsets edgeInsets;
// in implementation
- (void)viewDidLoad
{
[super viewDidLoad];
self.texts = @[
@"Text for row 0",
@"Text for row 1",
@"Text for row 2",
];
self.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
self.edgeInsets = UIEdgeInsetsMake(10, 20, 10, 10);
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [BTLabel heightForWidth:tableView.bounds.size.width
text:self.texts[indexPath.row]
font:self.font
edgeInsets:self.edgeInsets
numberOfLines:0
imageSize:CGSizeZero
imagePosition:UIRectEdgeTop
imageEdgeInsets:UIEdgeInsetsZero] + 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * const kCellID = @"kCellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID];
BTLabel *label = [[BTLabel alloc] initWithFrame:cell.bounds];
label.tag = 100;
label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
label.font = self.font;
label.textAlignment = NSTextAlignmentLeft;
label.verticalAlignment = BTVerticalAlignmentTop;
label.edgeInsets = self.edgeInsets;
label.hasImage = NO;
[cell.contentView addSubview:label];
}
BTLabel *label = [cell viewWithTag:100];
label.text = self.texts[indexPath.row];
return cell;
}
BTLabel is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "BTLabel"
Денис Либит, bteapot@me.com
BTLabel is available under the MIT license. See the LICENSE file for more info.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。