-
[iOS/UIToolbar] UIToolbar의 tintColor와 배경색backgroundColor앱등이에게 살충제를 뿌린다./iOS 2016. 7. 26. 13:36
<UIDdalba>
UIToolbar의 컬러에 대해서 생각해봅시다.
<<예제를 위해 싱글뷰 앱 프로젝트를 하나 만들어서 ViewController.swift파일만 조금 수정해줬습니다>>
<<참고로 UINavigationController에는 toolbar가 기본적으로 딸려 있습니다>>
navigationController.toolbarHidden = false를 적용 해보세요^^
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 charactersimport UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() navigationController?.toolbarHidden = false toolbarItems = makeToolbarItems() } private func makeToolbarItems() -> [UIBarButtonItem] { let space = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: self, action: nil) let edgeSpace = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: self, action: nil) let buttonItem1 = UIBarButtonItem(barButtonSystemItem: .Action, target: nil, action: nil) let buttonItem2 = UIBarButtonItem(barButtonSystemItem: .Bookmarks, target: nil, action: nil) let buttonItem3 = UIBarButtonItem(barButtonSystemItem: .Camera, target: nil, action: nil) let buttonItem4 = UIBarButtonItem(barButtonSystemItem: .Search, target: nil, action: nil) let buttonItem5 = UIBarButtonItem(barButtonSystemItem: .Refresh, target: nil, action: nil) return [edgeSpace, buttonItem1, space, buttonItem2, space, buttonItem3, space, buttonItem4, space, buttonItem5, edgeSpace] } } 결과화면
그렇다면 저 파란색은 어떻게 바꿀까요?
viewDidLoad에 한 줄만 추가해볼게요.
tintColor가 변경되었습니다.
그렇다면 배경색은 어떻게 바꿀까요? toolbar.backgroundColor??
아닙니다. 바로 barTintColor라는 프로퍼티를 수정해주어야 합니다.
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 charactersoverride func viewDidLoad() { super.viewDidLoad() navigationController?.toolbarHidden = false toolbarItems = makeToolbarItems() navigationController?.toolbar.tintColor = UIColor.redColor() navigationController?.toolbar.backgroundColor = UIColor.blueColor() navigationController?.toolbar.barTintColor = UIColor.blackColor() } 툴바의 배경색이 파란색이 아닌 검정으로 나타난거 보이시나요?
끝
'앱등이에게 살충제를 뿌린다. > iOS' 카테고리의 다른 글
[iOS] dismissBlock이라는 프로퍼티를 이용해보자. (0) 2016.08.13 [iOS] UIButton의 중복터치를 막아라 (0) 2016.07.29 WWDC 2016 키노트 다시보기 (0) 2016.06.14 UITabBarController에 탭바를 버튼처럼 사용하기. feat.인스타그램 (2) 2016.05.30 [iOS/Swift] XML 파싱하기 (0) 2016.05.10