【问题标题】:Is it possible to draw online image on tab bar item?是否可以在标签栏项目上绘制在线图像?
【发布时间】:2018-08-29 06:46:50
【问题描述】:

我想把在线图片放在标签栏项目上。

这在 iOS 中可行吗?

【问题讨论】:

    标签: ios image tabbar react-native-navigation


    【解决方案1】:

    您可以使用 WebImage 并使用 SDWebImage 加载它。

    https://github.com/rs/SDWebImage

    因此,一旦它加载并且您在其方法中获得 UIImage 的对象,您可以检查 UIImage 对象不应为 nil 如果不是 nil,则将 UIImage 设置为您的标签栏项目图像。

    imageView.sd_setImageWithURL(NSURL(string: urlString), completed: {
                (image, error, cacheType, url) in
                // Change tabbar item image here....
    
               tabHome.image=image?.withRenderingMode(.alwaysOriginal) // deselect image
               tabHome.selectedImage = image?.withRenderingMode(.alwaysOriginal) // select image
    
    
            })
    

    参考:how to set image in a tab bar item in swift?

    【讨论】:

    • 谢谢伙计。这个问题和答案都以意想不到的方式帮助了我。有时,只需要一两行来启发代码。 :)
    【解决方案2】:

    这可以通过UITabBarItem 在 iOS 中实现 您需要为您的业务选择 UITabBarItem 构造函数并设置图像

    UITabBarItem(title: String?, image: UIImage?, selectedImage: UIImage?)
    UITabBarItem(title: String?, image: UIImage?, tag: Int)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-05
      • 1970-01-01
      • 1970-01-01
      • 2010-12-23
      • 2012-01-03
      • 1970-01-01
      • 2011-05-03
      相关资源
      最近更新 更多