2016-11-02 1 views
1

에 UILabel의 둥근 모서리 텍스트를 사용하는 내가 레이블처럼이,방법 아이폰

& text should be like this

나는 다른 글꼴 색이 하나의 레이블을 표시하고자합니다.

즉,

"첫 번째"문자열은 빨간색이어야합니다.

"&"텍스트는 roundcornerd 및 lightgraycolor이어야합니다.

답변

0

 NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:singlestoreNode.objSeName]; 
       [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,2)]; 
       [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(2,3)]; 

       yourlable.attributedText = string; 

yourlable.layer.cornerRadius = 8.0; 
0

당신은 달성 할 수있는 시도를 사용 NSAttributedString은 그 3 개 라벨을 만들어.

설정이 같은 레이블의 색상 : "&"의 배경 라운드 들어

NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:lblTemp.text]; 
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)]; 
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5,6)]; 
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(11,5)]; 
lblTemp.attributedText = string; 

는 다음을 수행 할 수 있습니다

[yourUILabel sizeToFit]; 
yourUILabel.backgroundColor = [UIColor lightGrayColor]; 
yourUILabel.layer.masksToBounds = YES; 
yourUILabel.layer.cornerRadius = yourUILabel.frame.size.width/2; 

그런 다음 당신은 모든 것을 정렬해야합니다.

+0

UILabel이 하나 뿐인 경우 다른 솔루션은 "&" –

+0

예 뒤에 라운드 UVEi를 배치하는 것이지만 서버의 데이터에 따라 레이블의 크기가 줄어들거나 늘어날 수 있습니다 ..... thnks for 알리는 방법 –