UILabel *label = [[UILabel alloc] initWithFrame:self.view.bounds];label.text = @"各種居中";label.textAlignment = UITextAlignmentCenter;
[self.view addSubview:label];[object Object]
2 回答

守著一只汪
TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊
@implementation UILabel (VerticalUpAlignment)- (void)verticalUpAlignmentWithText:(NSString *)text maxHeight:(CGFloat)maxHeight { CGRect frame = self.frame; CGSize size = [text sizeWithFont:self.font constrainedToSize:CGSizeMake(frame.size.width, maxHeight)]; frame.size = CGSizeMake(frame.size.width, size.height); self.frame = frame; self.text = text; }@end
- 2 回答
- 0 關(guān)注
- 234 瀏覽
添加回答
舉報(bào)
0/150
提交
取消