iOS Label Text를 가운데 정렬하기

|

개인공부 후 자료를 남기기 위한 목적임으로 내용 상에 오류가 있을 수 있습니다.


Label Text를 가운데 정렬하기

이렇게 간단한걸 왜 굳이 정리하지? 싶겠지만…. 네 그렇습니다.
일반적으로 텍스트를 가운데 정렬하기 위해서는 아래와 같이 코드를 작성하면 됩니다.

self.titleLbl.textAlignment = .center

그런데 우리가 보통 텍스트의 속성을 건들기 위해서 NSMutableAttributedString 이 친구를 사용하는 경우가 있습니다.
이 친구를 사용하다보면 이상하게도 위에서 가운데 정렬을 하던 코드가 제대로 동작을 하지 않게 됩니다.

그때는 아래와 같은 방법을 사용해줍니다!

let attrString = NSMutableAttributedString(string: self.titleLbl.text ?? "")
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center

attrString.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: attrString.length))

self.titleLbl.attributedText = attrString

iOS Xcode 디바이스 빌드 실패(The operation couldn’t be completed) 해결방법

|

개인공부 후 자료를 남기기 위한 목적임으로 내용 상에 오류가 있을 수 있습니다.


Xcode 빌드 실패?

시뮬레이션에서도 문제 없었고 빌드도 잘되었는데, 아래와 같은 에러가 뜬다.

Could not launch "ProjectName"

The operation couldn’t be completed. Unable to launch opendoorLife.NavigationBarCheck because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user.

실제 디바이스에서 설정 문제입니다 :)
해결방법은 아래와 같습니다.

  1. 아이폰 설정(Setting) > 일반(General) 클릭
  2. VPN 및 기기 관리(Device Management) 클릭
  3. 빌드 시키고자 하는 앱 선택
  4. 개발자 신뢰를 위한~ 어쩌고 팝업 뜨면 신뢰 클릭

완료입니다

iOS WKWebkit view에 round(corner radius) 넣어주기

|

개인공부 후 자료를 남기기 위한 목적임으로 내용 상에 오류가 있을 수 있습니다.


WKWebkit view에 round(corner radius) 넣어주기

webkit view에 corner radius 를 적용하려니 되지 않더군요?

기존코드는 아래와 같습니다.

webView.layer.cornerRadius = 12

실제 코드가 작동하기 위해서 아래 코드를 추가해줍니다.

webView.layer.masksToBounds = true 

iOS TextField에 그림자 넣어주는 방법

|

개인공부 후 자료를 남기기 위한 목적임으로 내용 상에 오류가 있을 수 있습니다.


TextField에 그림자 넣어주는 방법

self.textField.backgroundColor = ColorTheme(background: .white)
self.textField.borderStyle = .none
self.textField.layer.cornerRadius = 12
self.textField.layer.shadowOpacity = 0.5
self.textField.layer.shadowRadius = 0.3
self.textField.layer.shadowOffset = CGSize(width: 0, height: 2)
self.textField.layer.shadowColor = ColorTheme(foreground: .black100).withAlphaComponent(0.05).cgColor

iOS TextField에 비밀번호를 입력하는 경우 (*)로 보이게 하는 방법

|

개인공부 후 자료를 남기기 위한 목적임으로 내용 상에 오류가 있을 수 있습니다.


TextField에 (*)로 보이게 하는 방법

textField.isSecureTextEntry = true