声网的实例代码 iOS 配置, 基本完成

将 Xcode 的

Bundle Identifier

io.agora.InteractivePodcast

这个是,master / owner

改为

io.agora.Intera

这个是参与者,游客






struct BuildConfig {


   // 声网
   
   // Agora App Id

    static let AppId = "81cf3717bea24aaaac1ba3e7a226d5a4"
    
    // 777
    static let Token = "00681cf3717bea24aaaac1ba3e7a226d5a4IABu118mDI/FBwAEJ17uLpaKNO2ZtTl/0FB9Vha4DflljTwv3/YAAAAAEABr21wCNMKQYQEAAQAzwpBh"
    

   // Lean Cloud 直接创建

    static let LeanCloudAppId = "9wnMCYCLJyFx4dL5uuLhmk4f-gzGzoHsz"
    static let LeanCloudAppKey = "9T6PiEkMqO6h7VuOGqPvg0r8"
    static let LeanCloudServerUrl = "https://9wnmcycl.lc-cn-n1-shared.com"
    




“777”

网页创建临时 token 的时候,手动填入的


.concatMap { result -> Observable<Result<Void>> in
                        return result.onSuccess {
                            // set default status when join room
                            member.isMuted = false
                            member.isSpeaker = room.anchor.id == user.id
                            member.isManager = room.anchor.id == user.id
                            member.isSelfMuted = false
                            //member.room = room
                            member.user = user
                            return Observable.just(result)
                        }
                    }
                    .concatMap { result -> Observable<Result<Room>> in
                        return result.onSuccess { Room.getRoom(by: room.id) }
                    }
                    .concatMap { result -> Observable<Result<Void>> in
                        return result.onSuccess { self.rtcServer.joinChannel(member: member, channel: "777", setting: self.setting) }
                    }
                    .concatMap { result -> Observable<Result<Void>> in
                        member.room = room
                        return result.onSuccess { self.member!.join(streamId: self.rtcServer.uid) }
                    }





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的 iOS 自定义 View 实现 K 线图的示例代码: ```swift import UIKit class KLineChartView: UIView { // K线图数据 var data: [KLineChartData] = [] // K线图相关配置 var config: KLineChartConfig = KLineChartConfig() // Y轴最大值 var yAxisMaxValue: CGFloat = 0 // Y轴最小值 var yAxisMinValue: CGFloat = 0 override func draw(_ rect: CGRect) { super.draw(rect) guard let context = UIGraphicsGetCurrentContext() else { return } // 绘制背景色 context.setFillColor(config.backgroundColor.cgColor) context.fill(rect) // 计算 Y 轴最大值和最小值 calculateYAxisValue() // 绘制 Y 轴 drawYAxis(context: context) // 绘制 K 线图 drawKLineChart(context: context) } // 计算 Y 轴最大值和最小值 private func calculateYAxisValue() { var maxValue: CGFloat = 0 var minValue: CGFloat = CGFloat.greatestFiniteMagnitude for item in data { if item.high > maxValue { maxValue = item.high } if item.low < minValue { minValue = item.low } } yAxisMaxValue = maxValue yAxisMinValue = minValue } // 绘制 Y 轴 private func drawYAxis(context: CGContext) { context.setStrokeColor(config.yAxisColor.cgColor) context.setLineWidth(config.yAxisLineWidth) // 计算 Y 轴刻度值 let stepValue = (yAxisMaxValue - yAxisMinValue) / CGFloat(config.yAxisTickCount - 1) for i in 0..<config.yAxisTickCount { // 计算 Y 轴刻度值对应的坐标 let y = bounds.height - CGFloat(i) / CGFloat(config.yAxisTickCount - 1) * bounds.height // 绘制 Y 轴刻度线 context.move(to: CGPoint(x: 0, y: y)) context.addLine(to: CGPoint(x: config.yAxisTickLength, y: y)) context.strokePath() // 绘制 Y 轴刻度值 let textRect = CGRect(x: 0, y: y - config.yAxisTickTextSize / 2, width: config.yAxisTickTextSize, height: config.yAxisTickTextSize) let text = String(format: "%.2f", yAxisMinValue + CGFloat(i) * stepValue) let attributes: [NSAttributedString.Key: Any] = [.foregroundColor: config.yAxisTextColor, .font: UIFont.systemFont(ofSize: config.yAxisTickTextSize)] let attributedText = NSAttributedString(string: text, attributes: attributes) attributedText.draw(in: textRect) } } // 绘制 K 线图 private func drawKLineChart(context: CGContext) { let barWidth = bounds.width / CGFloat(data.count) for (index, item) in data.enumerated() { let x = CGFloat(index) * barWidth + barWidth / 2 let highY = bounds.height - (item.high - yAxisMinValue) / (yAxisMaxValue - yAxisMinValue) * bounds.height let lowY = bounds.height - (item.low - yAxisMinValue) / (yAxisMaxValue - yAxisMinValue) * bounds.height let openY = bounds.height - (item.open - yAxisMinValue) / (yAxisMaxValue - yAxisMinValue) * bounds.height let closeY = bounds.height - (item.close - yAxisMinValue) / (yAxisMaxValue - yAxisMinValue) * bounds.height // 绘制 K 线图 context.setStrokeColor(item.color.cgColor) context.setLineWidth(config.kLineWidth) context.move(to: CGPoint(x: x, y: highY)) context.addLine(to: CGPoint(x: x, y: lowY)) context.strokePath() // 绘制 K 线实体 if item.close > item.open { context.setFillColor(config.riseColor.cgColor) } else { context.setFillColor(config.fallColor.cgColor) } let bodyRect = CGRect(x: x - config.kLineBodyWidth / 2, y: min(openY, closeY), width: config.kLineBodyWidth, height: abs(openY - closeY)) context.fill(bodyRect) } } } // K线图数据结构体 struct KLineChartData { var open: CGFloat = 0 // 开盘价 var close: CGFloat = 0 // 收盘价 var high: CGFloat = 0 // 最高价 var low: CGFloat = 0 // 最低价 var color: UIColor = .black // 颜色 } // K线图配置 struct KLineChartConfig { var backgroundColor: UIColor = .white // 背景色 var yAxisColor: UIColor = .black // Y轴颜色 var yAxisLineWidth: CGFloat = 1 // Y轴线宽 var yAxisTextColor: UIColor = .black // Y轴文本颜色 var yAxisTickTextSize: CGFloat = 10 // Y轴刻度值文本大小 var yAxisTickCount: Int = 5 // Y轴刻度值数量 var yAxisTickLength: CGFloat = 5 // Y轴刻度线长度 var kLineWidth: CGFloat = 1 // K线线宽 var kLineBodyWidth: CGFloat = 6 // K线实体宽度 var riseColor: UIColor = .red // 上涨颜色 var fallColor: UIColor = .green // 下跌颜色 } ``` 使用方法: ```swift let kLineChartView = KLineChartView(frame: CGRect(x: 0, y: 0, width: 300, height: 200)) kLineChartView.data = [ KLineChartData(open: 100, close: 120, high: 125, low: 95, color: .black), KLineChartData(open: 120, close: 110, high: 135, low: 105, color: .black), KLineChartData(open: 110, close: 130, high: 140, low: 100, color: .black), KLineChartData(open: 130, close: 115, high: 145, low: 110, color: .black), KLineChartData(open: 115, close: 125, high: 130, low: 105, color: .black), KLineChartData(open: 125, close: 135, high: 140, low: 120, color: .black), KLineChartData(open: 135, close: 120, high: 145, low: 115, color: .black), ] kLineChartView.config.yAxisTickCount = 5 kLineChartView.config.kLineBodyWidth = 4 kLineChartView.config.riseColor = .red kLineChartView.config.fallColor = .green view.addSubview(kLineChartView) ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值