0

У меня есть вот такой экран:

введите сюда описание изображения

Вот мой код:

struct Video {
    var image: UIImage
    var title: String
}

class VideoCell: UITableViewCell {

    @IBOutlet weak var videoImageView: UIImageView!
    @IBOutlet weak var videoTitleLabel: UILabel!

    func setVideo(video: Video) {
        videoImageView.image = video.image
        videoTitleLabel.text = video.title
    }
}


class VideoListScreen: UIViewController {

    @IBOutlet weak var tableView: UITableView!

    var videos: [Video] = []


    override func viewDidLoad() {
        super.viewDidLoad()
        videos = createArray()
    }


    func createArray() -> [Video] {

        let video1 = Video(image: #imageLiteral(resourceName: "beginner-first-app"), title: "Your First App")
        let video2 = Video(image: #imageLiteral(resourceName: "dev-setup"), title: "My Dev Setup")
        let video3 = Video(image: #imageLiteral(resourceName: "int-overview"), title: "iOS Interview")
        let video4 = Video(image: #imageLiteral(resourceName: "ss-delegates"), title: "Buttons in TableViews")
        let video5 = Video(image: #imageLiteral(resourceName: "ss-uipickerview-card"), title: "UIPickerView Tutorial")
        let video6 = Video(image: #imageLiteral(resourceName: "vlog-4"), title: "Day in the Life")

        return [video1, video2, video3, video4, video5, video6]
    }
}


extension VideoListScreen: UITableViewDataSource, UITableViewDelegate {

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return videos.count
    }


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let video = videos[indexPath.row]
        let cell = tableView.dequeueReusableCell(withIdentifier: "VideoCell") as! VideoCell
        cell.setVideo(video: video)

        return cell
    }
}

Я хочу поменять цвет шрифта у лейбла, но у меня не получается. Пыталась сделать в методе cellForRowAt Так как он находится в VideoCell, а не в контроллере, подскажите как сделать?

1 ответ 1

0

в методе cellForRowAt cell.videoTitleLabel.textColor = .red

2
  • Извиняюсь, описалась. У меня закрасился весь лейб, а мне нужно поменять цвет шрифта у лейбла
    – Yana
    21 мая 2020 в 13:09
  • @Yana исправил ответ
    – schmidt9
    21 мая 2020 в 13:31

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.