第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

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

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

收到一只叮咚 2019-09-18 13:29:02
我有一個(gè)名為“theImageView”的UIImageView,UIImage為單色(透明背景),就像下面的左黑心一樣。如何根據(jù)iOS 7+導(dǎo)航欄圖標(biāo)中使用的色調(diào)方法在iOS 7或更高版本中以編程方式更改此圖像的色調(diào)?這種方法也適用于Apple Watch應(yīng)用程序的WatchKit嗎?
查看完整描述

3 回答

?
動漫人物

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超10個(gè)贊

這是一個(gè)應(yīng)該做的技巧


@interface UIImage(Overlay)

@end


@implementation UIImage(Overlay)


- (UIImage *)imageWithColor:(UIColor *)color1

{

        UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);

        CGContextRef context = UIGraphicsGetCurrentContext();

        CGContextTranslateCTM(context, 0, self.size.height);

        CGContextScaleCTM(context, 1.0, -1.0);

        CGContextSetBlendMode(context, kCGBlendModeNormal);

        CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);

        CGContextClipToMask(context, rect, self.CGImage);

        [color1 setFill];

        CGContextFillRect(context, rect);

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        return newImage;

}

@end

所以你會這樣做:


theImageView.image = [theImageView.image imageWithColor:[UIColor redColor]];


查看完整回答
反對 回復(fù) 2019-09-18
?
蠱毒傳說

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊

我必須在Swift中使用extension。


我以為我會分享我是如何做到的:


extension UIImage {

    func imageWithColor(color1: UIColor) -> UIImage {

        UIGraphicsBeginImageContextWithOptions(self.size, false, self.scale)

        color1.setFill()


        let context = UIGraphicsGetCurrentContext() as CGContextRef

        CGContextTranslateCTM(context, 0, self.size.height)

        CGContextScaleCTM(context, 1.0, -1.0);

        CGContextSetBlendMode(context, CGBlendMode.Normal)


        let rect = CGRectMake(0, 0, self.size.width, self.size.height) as CGRect

        CGContextClipToMask(context, rect, self.CGImage)

        CGContextFillRect(context, rect)


        let newImage = UIGraphicsGetImageFromCurrentImageContext() as UIImage

        UIGraphicsEndImageContext()


        return newImage

    }

}

用法:


theImageView.image = theImageView.image.imageWithColor(UIColor.redColor())


斯威夫特4


extension UIImage {

    func imageWithColor(color1: UIColor) -> UIImage {

        UIGraphicsBeginImageContextWithOptions(self.size, false, self.scale)

        color1.setFill()


        let context = UIGraphicsGetCurrentContext()

        context?.translateBy(x: 0, y: self.size.height)

        context?.scaleBy(x: 1.0, y: -1.0)

        context?.setBlendMode(CGBlendMode.normal)


        let rect = CGRect(origin: .zero, size: CGSize(width: self.size.width, height: self.size.height))

        context?.clip(to: rect, mask: self.cgImage!)

        context?.fill(rect)


        let newImage = UIGraphicsGetImageFromCurrentImageContext()

        UIGraphicsEndImageContext()


        return newImage!

    }

}

用法:


theImageView.image = theImageView.image?.imageWithColor(color1: UIColor.red)


查看完整回答
反對 回復(fù) 2019-09-18
  • 3 回答
  • 0 關(guān)注
  • 679 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號