Saturday, November 7, 2026
HomeiOS Developmentios - Initializing UIView with parameters

ios – Initializing UIView with parameters

[ad_1]

UIView:

class TestUIVew: UIView {
    let dateLabel = UILabel()
    let dayLabel = UILabel()
    let tempDayLabel = UILabel()
    let tempNightLabel = UILabel()
    override init(body: CGRect) {
        tremendous.init(body: body)
        backgroundColor = .crimson
    }
    comfort init(body: CGRect, date: String, day: String, tempDay: Int, tempNight: Int) {
        self.init(body: body)
        self.dateLabel.body = CGRect(x: 10, y: 5, width: 100, top: 15)
        self.dateLabel.font = UIFont.systemFont(ofSize: 13.0)
        self.dateLabel.textual content = date
        /* configuring Uilabels */
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been applied")
    }
}

Making a UIView within the controller:

let take a look at = TestUIVew(
            body: CGRect(x: 0, y: 100, width: UIScreen.most important.bounds.width, top: 40),
            date: "февр. 18",
            day: "Сегодня",
            tempDay: +3,
            tempNight: +1)
        
view.addSubview(take a look at)

A UIView seems with a crimson background, however the labels are usually not displayed, why?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments