前提・実現したいこと
UIscrollViewにfor文を使って文字を並べて表示させるため下記のようなプログラムを書いたのですが、なぜか最後の文字しか表示されずそれまでの文字は表示されません。どうしてでしょうか
該当のソースコード
swift
1 scrollView.backgroundColor = UIColor.clear 2 // 表示窓のサイズと位置を設定 3 scrollView.frame.size = CGSize(width:width, height:height-height*118/1136) 4 scrollView.center = CGPoint(x: width/2, y: height/2+height*59/1136) 5 // 中身の大きさを設定 6 scrollView.contentSize = CGSize(width: width, height:height*12320/1136) 7 // スクロールの跳ね返り 8 scrollView.bounces = false 9 // スクロールバーの見た目と余白 10 scrollView.indicatorStyle = .white 11 scrollView.scrollIndicatorInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10) 12 // ScrollViewの中身を作る 13 setstage() 14 self.view.addSubview(scrollView)
swift
1//setstage内 2 rectlabel[count].text = String(count+1) 3 rectlabel[count].font = UIFont(name: "SourceHanSans-Bold", size: width*45/640) 4 rectlabel[count].sizeToFit() 5 rectlabel[count].textColor = UIColor.black 6 rectlabel[count].center = CGPoint(x:rx,y:ry) 7 scrollView.addSubview(rectlabel[count])
countを増やしていくことによりいくつかのlabelを描画しています
rxやryなどは正しい値になっていることは確認済みです
###バージョン
swift4
###補足
swift
1var rectlabel:[UILabel] = [] 2let samplelabel = UILabel.init() 3 //viewDidLoad()内 4rectlabel = Array(repeating: samplelabel, count: 500)
文字だけでなくlabel自体が表示されていないです
回答1件
あなたの回答
tips
プレビュー