swift 怎么修改controllerps修改背景颜色色

Swift开发教程--设置UIViewController的背景透明
时间: 16:22:09
&&&& 阅读:168
&&&& 评论:
&&&& 收藏:0
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&很简单的一句代码
self.view.backgroundColor =
UIColor.clearColor()
由此联想开来,很多的控件想设置为背景透明都可以用UIColor.clearColor()
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&原文:http://blog.csdn.net/wanglixin1999/article/details/
&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!Swift修改表格选中单元格(Cell)的样式(背景色,文字颜色)-ios7教程-手机开发-壹聚教程网Swift修改表格选中单元格(Cell)的样式(背景色,文字颜色)
下面我们来看一篇关于Swift修改表格选中单元格(Cell)的样式(背景色,文字颜色)的例子,希望这篇文章能够对各位带来帮助。
使用 tableView 时,默认选中单元格的背景颜色是灰色的,如下图:
1,使用自定义的背景颜色
这时就需要自定义 UITableViewCell 选中时背景View,并设置其颜色
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
&&& var tableView:UITableView?
&&& override func loadView() {
&&&&&&& super.loadView()
&&& override func viewDidLoad() {
&&&&&&& super.viewDidLoad()
&&&&&&& //创建表视图
&&&&&&& self.tableView = UITableView()
&&&&&&& self.tableView!.frame = CGRectMake(0, 0, self.view.frame.width,
&&&&&&&&&&& self.view.frame.height)
&&&&&&& self.tableView!.delegate = self
&&&&&&& self.tableView!.dataSource = self
&&&&&&& //创建一个重用的单元格
&&&&&&& self.tableView!.registerClass(UITableViewCell.self,
&&&&&&&&&&& forCellReuseIdentifier: &SwiftCell&)
&&&&&&& self.view.addSubview(self.tableView!)
&&& //在本例中,只有一个分区
&&& func numberOfSectionsInTableView(tableView: UITableView) -& Int {
&&&&&&& return 1;
&&& //返回表格行数(也就是返回控件数)
&&& func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -& Int {
&&&&&&& return 20
&&& //创建各单元显示内容(创建参数indexPath指定的单元)
&&& func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
&&&&&&& -& UITableViewCell
&&&&&&& //为了提供表格显示性能,已创建完成的单元需重复使用
&&&&&&& let identify:String = &SwiftCell&
&&&&&&& //同一形式的单元格重复使用,在声明时已注册
&&&&&&& let cell = tableView.dequeueReusableCellWithIdentifier(identify,
&&&&&&&&&&& forIndexPath: indexPath) as UITableViewCell
&&&&&&& cell.textLabel?.text = &条目\(indexPath.row)&
&&&&&&& //选中背景修改成绿色
&&&&&&& cell.edBackgroundView = UIView()
&&&&&&& cell.selectedBackgroundView?.backgroundColor =
&&&&&&&&&&& UIColor(red: 135/255, green: 191/255, blue: 49/255, alpha: 1)
&&&&&&& return cell
&&& override func didReceiveMemoryWarning() {
&&&&&&& super.didReceiveMemoryWarning()
2,改变选中单元格的文字颜色
通过 cell 内文本标签的 textColor 和 highlightedTextColor 属性,可以分别设置文字默认颜色和选中颜色。
//默认文字颜色是黑色,选中项文字是白色
cell.textLabel?.textColor = UIColor.blackColor()
cell.textLabel?.highlightedTextColor = UIColor.whiteColor()
名称:大小:9.96MM下载:
上一页: &&&&&下一页:相关内容ios开发之Swift标签栏按钮UITabBarItem样式修改(图标文字尺寸,颜色等)-ios7教程-手机开发-壹聚教程网ios开发之Swift标签栏按钮UITabBarItem样式修改(图标文字尺寸,颜色等)
UITabBarItem在开发中非常的常用了它可以用来设置字体颜色及图片的设置等等,下面我们来看一篇关于ios开发之Swift标签栏按钮UITabBarItem样式修改(图标文字尺寸,颜色等)的例子,具体的细节如下所示。
1,tabBarItem图片的推荐尺寸和最大支持尺寸
下面是标签栏(UITabBar)中tab按钮图标分别在1x、2x、3x下不会压缩变形的尺寸:
@1x&: 推荐 25 x 25 & (最大: 48 x 32)
@2x&: 推荐 50 x 50 & (最大: 96 x 64)
@3x&: 推荐 75 x 75 & (最大: 144 x 96)
下面是在2x下,左边使用50 x 50的图片,右边使用64 x 64的图片,大家可以比较下:
import UIKit
class MainTabViewController:UITabBarController
&&&&override func viewDidLoad()
&&&&&&&&super.viewDidLoad()
&&&&&&&&//一共包含了两个视图
&&&&&&&&let qqView = View1ViewController()
&&&&&&&&qqView.title = &QQ&
&&&&&&&&let androidView = View1ViewController()
&&&&&&&&androidView.title = &skype&
&&&&&&&&//分别声明两个视图控制器
&&&&&&&&let qq = UINavigationController(rootViewController:qqView)
&&&&&&&&qq.tabBarItem.image = UIImage(named:&qq&)
&&&&&&&&let android = UINavigationController(rootViewController:androidView)
&&&&&&&&android.tabBarItem.image = UIImage(named:&skype&)
&&&&&&&&self.viewControllers = [qq,android]
&&&&&&&&&&&&&&
&&&&&&&&//默认选中的是qq视图
&&&&&&&&self.edIndex = 0
2,修改图片和文字的颜色&
默认未选中标签的图片和文字是灰色的,选中的是蓝色的,下面修改成橙色:
(1)图片和文字同时改变
//图片文字一起变色
self.tabBar.tintColor = UIColor.orangeColor()
(2)只改变文字颜色
//改变文字颜色
UITabBarItem.appearance().setTitleTextAttributes(
&&&&[NSForegroundColorAttributeName: UIColor.grayColor()], forState:.Normal)
UITabBarItem.appearance().setTitleTextAttributes(
&&&&[NSForegroundColorAttributeName: UIColor.orangeColor()], forState:.Selected)
(3)只改变图片颜色
self.tabBar.tintColor = UIColor.orangeColor()
//文字颜色还原
UITabBarItem.appearance().setTitleTextAttributes(
&&&&[NSForegroundColorAttributeName: self.view.tintColor], forState:.Selected)
3,选中时、不选中时使用不同图片
默认标签选中、不选中都使用的是同一个图片,只是颜色不同。我们也可使用两张不同图片表示两种状态。
qq.tabBarItem = UITabBarItem(title: &QQ&, image: UIImage(named: &qq&),
&&&&selectedImage: UIImage(named: &qq_active&))
android.tabBarItem = UITabBarItem(title: &Android&, image: UIImage(named: &android&),
&&&&selectedImage: UIImage(named: &android_active&))
4,使用图片的原始颜色
默认不管原图是什么颜色,渲染器都会将渲染成单一颜色,虽说符合现在扁平化的趋势,但有时我们还是想要使用图片原来的样子。
如下样例,标签选中时使用不着色的原始图片(未选中仍然渲染成灰色,当然也可以使用原始图片)
qq.tabBarItem =& UITabBarItem(title: &QQ&, image: UIImage(named: &qq_color&),
&&&&selectedImage: UIImage(named: &qq_color&)?.imageWithRenderingMode(.AlwaysOriginal))
android.tabBarItem =& UITabBarItem(title: &Android&, image: UIImage(named: &android_color&),
&&&&selectedImage: UIImage(named: &android_color&)?.imageWithRenderingMode(.AlwaysOriginal))
名称:大小:9.96MM下载:
上一页: &&&&&下一页:相关内容

我要回帖

更多关于 ps修改背景颜色 的文章

 

随机推荐