3 Star 0 Fork 0

Gitee 极速下载 / BTLabel

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/bteapot/BTLabel
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

BTLabel

Version License Platform

UILabel subclass with vertical text alignment, insets, images and height calculation.

screenshot

Specifically designed to use with UITableView.

screenshot

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Examples

Simple initialization:

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;

Using within UITableViewCell:

// 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;
}

Installation

BTLabel is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "BTLabel"

Author

Денис Либит, bteapot@me.com

License

BTLabel is available under the MIT license. See the LICENSE file for more info.

Copyright (c) 2014 Денис Либит <bteapot@me.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

BTLabel 是 UILabel 子类,可以垂直对其文本,插入图片和计算高度 展开 收起
Objective-C
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Objective-C
1
https://gitee.com/mirrors/BTLabel.git
git@gitee.com:mirrors/BTLabel.git
mirrors
BTLabel
BTLabel
master

搜索帮助