티스토리 뷰
UIImage를 UIImageView에 넣어주고 Layer를 조정하여서 화면에 보여주는 부분을 둥글게 표현을 할 수 있습니다.
그렇지만, 이런것을 떠나서 UIImage 자체를 둥글게 표현을 하고 싶을 경우가 있을수도 있는데요.
이러한 부분은 다음과 같은 코딩으로 처리할수 있음.
구현을 UIImage에 Category를 사용하여서, 만들어주도록 합니다.
@implementation UIImage (Add)
- (UIImage*)cornerRadius:(const CGFloat)radius {
UIImage* image = self;
UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
const CGRect RECT = CGRectMake(0, 0, image.size.width, image.size.height);
[[UIBezierPath bezierPathWithRoundedRect:RECT cornerRadius:radius] addClip];
[image drawInRect:RECT];
UIImage* imageNew = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageNew;
}
@end
호출부는 다음과 같음.
UIImage* image = [[UIImage imageNamed:@"image.jpeg"] cornerRadius:10];
카테고리에 대한 설명은 하지 않겠습니다. ^^
'Mobile > iOS' 카테고리의 다른 글
[iOS]Storyboard segue 호출시 값전달 (0) | 2016.04.05 |
---|---|
[iOS]Layer를 사용하여 보여줄 View 변경 (0) | 2016.04.05 |
[iOS]UIImage를 사진 앨범에 저장하기 (0) | 2016.04.04 |
[iOS]performSelector의 메모리 leak warning (0) | 2016.04.04 |
[iOS]다른 앱 호출 (0) | 2016.03.30 |
- Total
- Today
- Yesterday
- Java
- tomcat
- ubuntu
- docker
- intellij
- golang
- war
- Xcode
- Linux
- ios
- Windows
- CentOS
- go
- MySQL
- Gradle
- Kotlin
- Codable
- SWIFT
- android
- nodejs
- enum
- Python
- github
- php
- cocoapods
- git
- Spring
- centos8
- rxswift
- windows10
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |