ios生成随机颜色

写demo,太需要这个随机颜色了,每次都懒得写,从网上找,但是找出来的又都是良莠不齐,还需要再修改。

是在懒得修改,就找了一个合适的,从自己的博客找,减少筛选代码的成本。

OC版本

复制代码
#import <UIKit/UIKit.h>

UIColor *RandomColor(void) {
    CGFloat red = (CGFloat)arc4random_uniform(256) / 255.0;
    CGFloat green = (CGFloat)arc4random_uniform(256) / 255.0;
    CGFloat blue = (CGFloat)arc4random_uniform(256) / 255.0;
    return [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
}

Swift版本

复制代码
import UIKit
extension UIColor {
    static func randomColor() -> UIColor {
        return UIColor(
            red: .random(in: 0...1),
            green: .random(in: 0...1),
            blue: .random(in: 0...1),
            alpha: 1.0
        )
    }
}
相关推荐
VicLi19 小时前
把常用 iOS 调试操作放进一个 macOS 控制台: iCATBox
ios
茶底世界之下19 小时前
雾景需要更强反差吗?用 Awaking 检查树影与雾气的平衡
ios
EVE จุ๊บ21 小时前
Mac安装Playwright
macos
终端安全笔记1 天前
下一个大版本要动的三处:更新指令、传输要求、策略写法
网络安全·ios·1024程序员节·移动设备管理
法的空间1 天前
AI 编程时代,为什么 Dart 分析会拖慢大型项目的开发
android·flutter·ios
season_zhu1 天前
Skills For Real Engineers 系列之二:grill,把需求想清楚,也别把自己问进死胡同
ios·ai编程
全栈探索者1 天前
出图模型怎么选?同一只猫的四场实测:Z-Image、Qwen-Image 2.1、SD1.5 三维对决
人工智能·macos·aigc·stablediffusion·comfyui
美狐美颜SDK开放平台2 天前
准备开发直播APP?视频美颜SDK接入前的十项检查清单
android·ios·音视频·直播美颜sdk·视频美颜sdk
加载力科技2 天前
Mac解压LZ4格式全攻略-免命令行极速解压
macos·mac 解压工具·乐压·mac 解压 lz4·lz4 格式·tar.lz4·极速解压
风别鹤2 天前
Xcode pod ‘xxx/xxx.h‘ file not found
ide·macos·xcode