栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在iOS和WatchKit中更改图像tintColor

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在iOS和WatchKit中更改图像tintColor

iOS对于iOS应用,在Swift 3、4或5中:

theImageView.image = theImageView.image?.withRenderingMode(.alwaysTemplate)theImageView.tintColor = UIColor.red

For Swift 2:

theImageView.image = theImageView.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)theImageView.tintColor = UIColor.redColor()

Meanwhile, the modern Objective-C solution is:

theImageView.image = [theImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];[theImageView setTintColor:[UIColor redColor]];

Watchkit
在Apple Watch应用程序的WatchKit中,您可以设置模板图像的色调颜色。

您必须将图像添加到WatchKitApp的资产目录中,并在AttributesInspector中将图像集设置为呈现为模板图像。与iPhone应用程序不同,当前无法在WatchKit Extension中的代码中设置模板渲染。
设置要在应用程序的界面生成器中的WKInterfaceImage中使用的图像在WKInterfaceController中为名为“ theImage”的WKInterfaceImage创建一个IBOutlet…然后在Swift 3或4中设置色调颜色:

theImage.setTintColor(UIColor.red)

Swift 2:

theImage.setTintColor(UIColor.redColor())

To then set the tint color in Objective-C:

[self.theImage setTintColor:[UIColor redColor]];

如果您使用模板图像且未应用色调颜色,则将应用WatchKit应用程序的“全局色调”。如果您尚未设置全局色调,

theImage
则在用作模板图像时默认情况下将淡蓝色。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/368754.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号