Skip to content

Instantly share code, notes, and snippets.

@ya-s-u
Created April 3, 2015 15:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ya-s-u/98e2fab4a88df426ec39 to your computer and use it in GitHub Desktop.
Save ya-s-u/98e2fab4a88df426ec39 to your computer and use it in GitHub Desktop.
タブバーのアイコン色(非選択時)
//
// TabMenuController.swift
// BeeApp
//
// Created by 後藤 誉昌 on 2015/04/03.
// Copyright (c) 2015年 Yasuaki Goto. All rights reserved.
//
import UIKit
class TabMenuController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
// 定数
let barColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1.0)
let normalColor = UIColor(red: 157/255, green: 181/255, blue: 192/255, alpha: 1.0)
let selectedColor = UIColor(red: 255/255, green: 193/255, blue: 33/255, alpha: 1.0)
// バーの背景色
UITabBar.appearance().barTintColor = barColor
// 通常の文字色
let normalAttributes: NSDictionary! = [NSForegroundColorAttributeName: normalColor]
UITabBarItem.appearance().setTitleTextAttributes(normalAttributes, forState: UIControlState.Normal)
// 通常のアイコン
var assets :Array<String> = ["img1", "img2", "img3", "img4"]
for (idx, item) in enumerate(self.tabBar.items as [UITabBarItem]) {
if let image = item.image {
item.image = UIImage(named: assets[idx])?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
}
}
// 選択時の文字色
let selectedAttributes: NSDictionary! = [NSForegroundColorAttributeName: selectedColor]
UITabBarItem.appearance().setTitleTextAttributes(selectedAttributes, forState: UIControlState.Selected)
// 選択時のアイコン色
UITabBar.appearance().tintColor = selectedColor
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment