반응형

iOS/코드조각 121

[iOS, Swift] UIImagePickerController 이미지 선택 화면 띄우기

iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다. class UIImagePickerViewController: UIViewController { let imagePickerController = UIImagePickerController() override func viewDidLoad() { super.viewDidLoad() imagePickerController.delegate = self imagePickerController.sourceType = .photoLibrary view.backgroundColor = .white self.present(imagePickerController, animated: true) } } extension UIImag..

iOS/코드조각 2022.08.21

[iOS, Swift] UIImage 그라데이션 그리기 (Gradient Image)

iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다. extension UIImage { static func gradientImageWithBounds(bounds: CGRect, colors: [CGColor]) -> UIImage { let gradientLayer = CAGradientLayer() gradientLayer.frame = bounds gradientLayer.colors = colors UIGraphicsBeginImageContext(gradientLayer.bounds.size) gradientLayer.render(in: UIGraphicsGetCurrentContext()!) let image = UIGraphicsGetImageFrom..

iOS/코드조각 2022.08.21

[iOS, Swift] LocalNotification Foreground 알림 받기

iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다. import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. // Delegate 등록, 없으면 실행 X UNUserNotificationCenter.current().delegate..

iOS/코드조각 2022.08.21

[iOS, Swift] LocalNotification 실행하기

iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다. import UserNotifications class ViewController: UIViewController { lazy var button: UIButton = { var button = UIButton(type: .custom) button.setTitle("알림", for: .normal) return button }() override viewDidLoad() { // Notification 알림 허용 UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { didAllow, Error in p..

iOS/코드조각 2022.08.21

[iOS, Swift] UILabel 텍스트 양쪽 정렬(Justify Text)

iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다. let loremText = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetti..

iOS/코드조각 2022.08.20

[iOS, Swift] UILabel TextColor 설정 (NSAttributedString)

iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다. label.textColor = UIColor.red // OR label.textColor = UIColor(red: 64/255, green: 88/255, blue: 41/255, alpha: 1) label.textColor 속성에 UIColor 값을 넣으면 UILabel Text 색 변경이 가능하다. let attributedString = NSMutableAttributedString(string: "The grass is green; the sky is blue.") attributedString.addAttribute(NSAttributedString.Key.foregroundColor, value:..

iOS/코드조각 2022.08.20
반응형