<iOS>arc4random

本文详细介绍了arc4random的基本用法,包括如何获取指定范围内的随机整数,适用于编程初学者和专业人士。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

arc4random常用方法

1、获取一个随机整数范围在:[0,100)包括0,不包括100

int x = arc4random() % 100;

2、获取一个随机数范围在:[500,1000),包括500,不包括1000

int y = (arc4random() % 500) + 500;

3、获取一个随机整数,范围在[from,to),包括from,不包括to

- (int)getRandomNumber:(int)from to:(int)to{

      return (int)(from + (arc4random()%(to - from)));

}

<template> <view class="progress-container"> <!-- 外层刻度 --> <view class="scale-container"> <view v-for="(item, index) in 12" :key="index" class="scale-item" :style="{ transform: `rotate(${index * 30}deg)`, backgroundColor: progress >= 100 ? '#5BCEFF' : '#3B82F6' }" ></view> </view> <!-- 进度条 --> <view class="progress-wrapper"> <svg class="progress-svg" viewBox="0 0 100 100" > <!-- 背景圆环 --> <circle cx="50" cy="50" :r="radius" fill="none" stroke="#F2F7FF" :stroke-width="strokeWidth" /> <!-- 进度圆环 --> <circle cx="50" cy="50" :r="radius" fill="none" :stroke="progress >= 100 ? 'url(#gradientComplete)' : 'url(#gradientIncomplete)'" :stroke-width="strokeWidth" :stroke-dasharray="circumference" :stroke-dashoffset="dashOffset" stroke-linecap="round" transform="rotate(-90 50 50)" /> <!-- 渐变色定义 --> <defs> <linearGradient id="gradientIncomplete" x1="0%" y1="0%" x2="100%" y2="0%"> <stop offset="0%" stop-color="#F2F7FF" /> <stop offset="100%" stop-color="#3B82F6" /> </linearGradient> <linearGradient id="gradientComplete" x1="0%" y1="0%" x2="100%" y2="0%"> <stop offset="0%" stop-color="#5BCEFF" /> <stop offset="100%" stop-color="#4BFF75" /> </linearGradient> </defs> </svg> <!-- 中间内容 --> <view class="progress-content"> <slot></slot> </view> </view> </view> </template> <script setup> import { computed } from 'vue' const props = defineProps({ progress: { type: Number, default: 0, validator: value => value >= 0 && value <= 100 }, // 圆环半径(基于viewBox的百分比) radius: { type: Number, default: 40 }, // 圆环宽度(基于viewBox的百分比) strokeWidth: { type: Number, default: 5 } }) // 计算圆周长 const circumference = computed(() => 2 * Math.PI * props.radius) // 计算进度偏移量 const dashOffset = computed(() => { const progress = Math.min(Math.max(props.progress, 0), 100) return circumference.value * (1 - progress / 100) }) </script> <style lang="scss" scoped> .progress-container { position: relative; width: 300rpx; height: 300rpx; display: flex; justify-content: center; align-items: center; } .progress-wrapper { position: relative; width: 100%; height: 100%; } .progress-svg { width: 100%; height: 100%; transform: rotate(0deg); } .progress-content { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 60%; height: 60%; border-radius: 50%; background-color: white; display: flex; justify-content: center; align-items: center; flex-direction: column; } .scale-container { position: absolute; width: calc(100% + 20rpx); height: calc(100% + 20rpx); top: -10rpx; left: -10rpx; } .scale-item { position: absolute; width: 4rpx; height: 10rpx; top: 0; left: 50%; transform-origin: 50% 150rpx; border-radius: 2rpx; } </style> 帮我将这个组件转化为可以适配Android,ios,小程序,pc得uniapp vue3代码
最新发布
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值