2017-06-01 48 views

回答

0

通过使用自定义框架初始化UILabel,可以从UILabel的左侧和右侧进行填充。

CGRect startFrame = CGRectMake(0, 0, 80, 80); 
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0, 10, 0, 0); 
CGRect padFrame = UIEdgeInsetsInsetRect(startFrame, contentInsets); 
self.yourLabel = [[UILabel alloc] initWithFrame: padFrame]; 
+0

标签设置在表视图中,我通过调用方法在cell.m文件中设置框架: - (void)setMessageLbl:(NSString *)text withlbl:(UILabel *)lbl {CGRect startFrame = CGRectMake((imageScrollView。 frame.size.width-20)-widthIs,message.frame.origin.y,widthIs + 10,16); UIEdgeInsets contentInsets = UIEdgeInsetsMake(0,5,0,5); CGRect padFrame = UIEdgeInsetsInsetRect(startFrame,contentInsets); lbl.frame = padFrame;} –

+0

取代你的cell.m – Ved

+0

self.frame = padFrame的最后一行,但我想通过做自我改变标签的框架,我认为它会采取单元格不是单元格的标签。但我尝试像这样:self.lbl.frame = padframe。但仍然没有改变。我使用自动布局,所以在改变框架后,我把[lbl setNeedsLayout]; [lbl setNeedsDisplay];代码也。 –

相关问题