아이폰 프로그램의 헤더 (내비게이션 표시줄) 색상 변경
6038 단어 Swift
요지
이 그림처럼 제작NavigationController
하면 변경NavigationBar
의 색깔, 제목의 색깔, 시간 표시와 배터리의 색깔을 바꾸는 방법을 소개한다.
절차.
Xcode로 Single View Apps를 제작한 상태부터 시작합니다.
XcodeMain.storyboard
가 표시된 상태에서 Editor > Embedin > Navigation Controller 를 선택합니다.
그러면 Navigation Controller가 추가될 것 같습니다.
그런 다음 Navigation Item을 View Controller 화면으로 드래그합니다.이렇게 하면 제목이 표시됩니다.
에서 내비게이션 표시줄의 색을 수정해야 하지만, 색 지정은 원본 코드에 설명됩니다.ViewController.swift
의viewDidLoad()
방법에서 다음과 같다.
ViewController.swiftimport UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController!.navigationBar.barStyle = .black
self.navigationController!.navigationBar.barTintColor = #colorLiteral(red: 0.1725490196, green: 0.1725490196, blue: 0.1725490196, alpha: 1)
self.navigationController!.navigationBar.tintColor = .white
self.navigationController!.navigationBar.titleTextAttributes = [
.foregroundColor: UIColor.white
]
}
}
보아하니 이렇다.
각 매개 변수는 아래의 그림입니다.tintColor
는 링크와 같이 네비게이션 항목의 색을 바꾸는 매개 변수이다.
색상 지정은 .white
, .blue
처럼 지정할 수도 있고, #colorLiteral(red: green: blue: alpha:)
처럼 지정하면 색상 팔레트를 열어 색상을 자세히 지정할 수도 있습니다.
barStyle
에 대해서는 default
(아무것도 지정하지 않음), black
, blackTrunslucent
세 가지 옵션 중에서 선택할 수 있습니다.default
의 상황은 다음과 같다.
blackTrunslucent
의 상황은 다음과 같다.black
랑 다를 게 없어...스크롤하면 배경이 투명할 줄 알았는데 아닌 것 같아.미안합니다.여기 잘 모르겠어요.
여기까지 읽어주셔서 감사합니다.
참고 자료
Xcode로 Single View Apps를 제작한 상태부터 시작합니다.
Xcode
Main.storyboard
가 표시된 상태에서 Editor > Embedin > Navigation Controller 를 선택합니다.그러면 Navigation Controller가 추가될 것 같습니다.
그런 다음 Navigation Item을 View Controller 화면으로 드래그합니다.이렇게 하면 제목이 표시됩니다.
에서 내비게이션 표시줄의 색을 수정해야 하지만, 색 지정은 원본 코드에 설명됩니다.
ViewController.swift
의viewDidLoad()
방법에서 다음과 같다.ViewController.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController!.navigationBar.barStyle = .black
self.navigationController!.navigationBar.barTintColor = #colorLiteral(red: 0.1725490196, green: 0.1725490196, blue: 0.1725490196, alpha: 1)
self.navigationController!.navigationBar.tintColor = .white
self.navigationController!.navigationBar.titleTextAttributes = [
.foregroundColor: UIColor.white
]
}
}
보아하니 이렇다.각 매개 변수는 아래의 그림입니다.
tintColor
는 링크와 같이 네비게이션 항목의 색을 바꾸는 매개 변수이다.색상 지정은
.white
, .blue
처럼 지정할 수도 있고, #colorLiteral(red: green: blue: alpha:)
처럼 지정하면 색상 팔레트를 열어 색상을 자세히 지정할 수도 있습니다.barStyle
에 대해서는 default
(아무것도 지정하지 않음), black
, blackTrunslucent
세 가지 옵션 중에서 선택할 수 있습니다.default
의 상황은 다음과 같다.blackTrunslucent
의 상황은 다음과 같다.black
랑 다를 게 없어...스크롤하면 배경이 투명할 줄 알았는데 아닌 것 같아.미안합니다.여기 잘 모르겠어요.여기까지 읽어주셔서 감사합니다.
참고 자료
Reference
이 문제에 관하여(아이폰 프로그램의 헤더 (내비게이션 표시줄) 색상 변경), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/Gattaca/items/5f85870e624735d272a9텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)