有的App后台网络颜色值使用的Android的int类型的颜色值。iOS使用RGBA的颜色值。怎么进行转换呢?

// Swiftfunc color(_ color: Int) -> UIColor {    let c: UInt32 = UInt32(color)    let alpha = CGFloat(c >> 24) / 255.0    let r = CGFloat((c & 0xff0000) >> 16) / 255.0    let g = CGFloat((c & 0xff00) >> 8) / 255.0    let b = CGFloat(c & 0xff) / 255.0    return UIColor.init(red: r, green: g, blue: b, alpha: alpha)}// Swiftfunc intColor(_ color: UIColor) -> Int {    let alpha: UInt32 =    ... 省略从UIColor获取r,g,b,alpha的代码    let intColor: UInt32 = (alpha << 24) | (r << 16) | (g << 8) | b;    return Int(intColor);}

注意:Android没有无符号整数,在获取alpha值的时候,要使用算术右移。示例如下:

// Javavoid printRGBA(int color) {    int alpha = color >>> 24;    int r = ( color & 0xff0000 ) >> 16;    int g = ( color & 0xff00 ) >> 8;    int b = color & 0xff;    System.out.println(alpha + ", " + r + ", " + g + ", " + b);}

更多相关文章

  1. Android调用微信登陆、分享、支付(第一版)
  2. Android底部导航栏BottomNavigatonView的使用方式
  3. Android(安卓)下载网络图片注意的问题
  4. 获得android 应用的版本和当前android系统版本
  5. android MotionEvent 获取长按压时间长
  6. TQ210搭载Android(安卓)4.0.3测试Google Maps API V2(一.获取地
  7. Android(安卓)BLE蓝牙开发中读取数据时设置Notify的方法
  8. Android写入内部存储和sd卡
  9. android中获取屏幕相关信息

随机推荐

  1. Android增加Activity background
  2. Android之启动页优化
  3. Android——系统提示对话框(AlertDialog)
  4. Android ScaleGestureDetector
  5. android raw 文件下写入数据库
  6. ANDROID上获取MSN邮件列表
  7. android activity以对话框形式显示
  8. android permission设置
  9. Android SDK Android NDK 下载地址
  10. ubuntu 18.04 编译Android坑s