'Dev/Objective-C'에 해당되는 글 11건
- 2019.12.31 [Objective-C] AFNetworking Tutorial with a Singleton Class
- 2019.10.14 [Objective-C] Category, Extention
- 2018.09.05 iOS 메모리관리
- 2018.06.22 [Objective-C] 오토릴리즈 풀
- 2018.06.22 [Objective-C] 프로퍼티에 대해서
- 2018.05.16 [Objective-C] UILabel 해당 택스트 컬러 변경 (AttributedString)
- 2018.04.26 [Objective-C] UIAlertController 사용시 패드에서 종료되는 문제
- 2018.04.26 [Objective-C] UIButton에 LongPressGesture 사용하기
- 2017.11.10 [Objective-C] UITextView에 커스텀 링크 연결
- 2017.10.30 [Objective-C] 버전 체크
Dev/Objective-C2019. 12. 31. 11:36
Dev/Objective-C2019. 10. 14. 13:04
Category
카테고리는 많은 수의 메소드를 포함하는 파일을 생성 할 때 사용됩니다. 따라서 단일 클래스를 다른 모듈로 분리하는 기능을 제공합니다. 또한 카테고리가 변경되면 컴파일러는 전체 프로젝트를 컴파일하는 데 시간을 낭비하지 않습니다. 카테고리는 새 변수 나 속성을 추가하고 상위 클래스까지 볼 수 없습니다. 카테고리의 메소드를 override 할 수는 있지만 좋은 생각이 아닙니다. 또한 모든 카테고리는 동일한 계층 수준을 수준을 가지므로 동일한 상위 클래스에 속하는 두 범주가 런타임에 존재할 수 있기 때문에 흐름이 영향을 받을 수 있습니다. 또한 보호 된 메소드는 카테고리를 사용하여 생성 될 수 있습니다.
Extention
확장을 사용하면 속성을 재정의하거나 기존 속성을 새 부모 클래스에 추가 할 수 있습니다. 이름이 없으며 @interface class() 로 표현되는 카테고리 와 구문 적으로 동일합니다. .m 파일이없고 extension에 선언 된 메소드가 parent 파일의 @implementation에 구현되어야합니다. 익명카테고리라고도 한다.
Dev/Objective-C2018. 9. 5. 16:26
Dev/Objective-C2018. 6. 22. 01:04
Dev/Objective-C2018. 6. 22. 00:55
Dev/Objective-C2018. 5. 16. 15:48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)boldRange:(NSRange)range; | |
- (void)boldSubstring:(NSString*)substring; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation UILabel (BoldRangeLabel) | |
- (void)boldRange:(NSRange)range { | |
if (![self respondsToSelector:@selector(setAttributedText:)]) { | |
return; | |
} | |
NSMutableAttributedString *attributedText; | |
if (!self.attributedText) { | |
attributedText = [[NSMutableAttributedString alloc] initWithString:self.text]; | |
} else { | |
attributedText = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedText]; | |
} | |
[attributedText setAttributes:@{NSForegroundColorAttributeName:[UIColor redColor], | |
NSFontAttributeName:[UIFont boldSystemFontOfSize:self.font.pointSize] | |
} | |
range:range]; | |
self.attributedText = attributedText; | |
} | |
- (void)boldSubstring:(NSString*)substring { | |
NSRange range = [self.text rangeOfString:substring]; | |
if (![self respondsToSelector:@selector(setAttributedText:)]) { | |
return; | |
} | |
NSMutableAttributedString *attributedText; | |
if (!self.attributedText) { | |
attributedText = [[NSMutableAttributedString alloc] initWithString:self.text]; | |
} else { | |
attributedText = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedText]; | |
} | |
while (range.location != NSNotFound) | |
{ | |
[attributedText setAttributes:@{NSForegroundColorAttributeName:[UIColor redColor], | |
NSFontAttributeName:[UIFont boldSystemFontOfSize:self.font.pointSize] | |
} | |
range:range]; | |
NSRange rangeToSearch; | |
rangeToSearch.location = range.location + range.length; | |
rangeToSearch.length = self.text.length - rangeToSearch.location; | |
range = [self.text rangeOfString:substring options:0 range:rangeToSearch]; | |
[attributedText setAttributes:@{NSForegroundColorAttributeName: [UIColor redColor], | |
NSFontAttributeName:[UIFont boldSystemFontOfSize:self.font.pointSize] | |
} | |
range:range]; | |
self.attributedText = attributedText; | |
} | |
} | |
@end |
Dev/Objective-C2018. 4. 26. 11:45
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define IS_IPAD [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad | |
- (IBAction)showAlert:(UIButton *)btn | |
{ | |
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; | |
[alert addAction:[UIAlertAction actionWithTitle:@"확인" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action){ | |
// 확인 | |
}]]; | |
[alert addAction:[UIAlertAction actionWithTitle:@"취소" style:UIAlertActionStyleCancel handler:NULL]]; | |
if (IS_IPAD){ | |
UIPopoverPresentationController *popPresenter = [alert popoverPresentationController]; | |
popPresenter.sourceView = sender; | |
popPresenter.sourceRect = sender.bounds; | |
} | |
[self presentViewController:alert animated:YES completion:NULL]; | |
} |
Dev/Objective-C2018. 4. 26. 11:07
Dev/Objective-C2017. 11. 10. 16:11
Dev/Objective-C2017. 10. 30. 17:31