logo

English

이곳의 프로그래밍관련 정보와 소스는 마음대로 활용하셔도 좋습니다. 다만 쓰시기 전에 통보 정도는 해주시는 것이 예의 일것 같습니다. 질문이나 오류 수정은 siseong@gmail.com 으로 주세요. 감사합니다.

iOS - UILabel 에서 AttributeString 사용하기

by digipine posted Nov 02, 2017
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

NSString *allString = @"Hello Nice to Meet you";    //전체 텍스트

NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString: allString];    //AttributeString으로 선언

NSRange sRange = [str rangeOfString:@"Nice"];     //Nice라는 글자의 위치가져오기

[attString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:sRange];     //attString의 Range위치에 있는 "Nice"의 글자의 색상을 변경

[testLabel setAttributedText:string];     //라벨에 SetText가 아닌 setAttributeText로 텍스트 설정

 

// Bold
[attr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:14.f] range:NSMakeRange(0, 13)];

// underline 효과
[attr addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(0, 13)];

// font 효과
[attr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:14] range:NSMakeRange(0, 13)];

// strike 효과 (@1은 선의 굵기)
[attr addAttribute:NSStrikethroughStyleAttributeName value:@1 range:NSMakeRange(0, 13)];

// 문장과 문장 사이의 간격 (여러줄일 경우)
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:8];
[paragraphStyle setAlignment:NSTextAlignmentCenter];
[attr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, 13)];

// 배경색
[attr addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 13)];

 
TAG •

List of Articles
No. Subject Author Date Views
35 iOS - UITextField의 Placeholder Color 색 변경하기 file digipine 2017.11.02 1152
34 iOS - BLE 장치용 ANCS Library for ANCS digipine 2017.11.02 949
» iOS - UILabel 에서 AttributeString 사용하기 digipine 2017.11.02 640
32 Apple AppStore App Review 시 Reject 피하기 위한 방법 digipine 2017.11.02 447
31 OpenAL PDF, Sample Source file digipine 2017.11.02 796
30 [iOS, MacOS] ATS 보안 정책 가이드 digipine 2017.11.02 567
29 [iOS, MacOS] NSArray 정렬 Sorting에 대해서 digipine 2017.11.02 663
28 [iOS, MacOS] Singleton 싱글톤 패턴 사용하기 2 digipine 2017.11.02 1080
27 [iOS, MacOS] NSNotification, NSNotificationCenter 사용법 digipine 2017.11.02 1026
26 XCode 8 업데이트 후 Code Sign Error 발생 시 해결법 1 digipine 2017.11.02 711
25 [Objective C] NSString 앞뒤 공백 문자 및 줄바꿈 문자 제거 digipine 2017.11.02 1655
24 [macOS] Sandbox 정책 극복기 Accessing Security Scoped Resource 1 file digipine 2017.11.02 1776
23 [Swift 3] HTTP Request 사용하기, 클래스 소스코드 및 사용법 digipine 2017.11.02 9668
22 [Swift 3] TCPIP Socket 통신 클래스 소스 코드 및 사용법 digipine 2017.11.02 4647
21 OSX 사파리 최신 버전 폰트 변경하기 file digipine 2017.11.03 1224
20 OSX - Screen Serial Terminal - OSX에서 시리얼 터미널 사용하기 digipine 2017.11.03 6868
19 MacOS mysql 비밀번호 분실 시 재설정하기 digipine 2017.11.14 1028
18 [Objective-C] NSOperation과 NSOperationQueue를 사용하는 방법 - 설명 및 예제 엉뚱도마뱀 2018.03.14 4191
17 [swift 4] 변경 사항 정리 file 엉뚱도마뱀 2018.07.23 1019
16 [swfit 4] 스위프트 Swift 동시성 동기화 정리 엉뚱도마뱀 2018.09.06 1315
Board Pagination Prev 1 2 3 Next
/ 3