2017-06-01 52 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];代碼也。 –

相關問題