В коде Swift моя метка не отображается в моем ViewController - PullRequest
0 голосов
/ 05 апреля 2019

Когда на телефоне отображается ViewController, ярлык не отображается

Я новичок в iOS и быстро, я часто ищу YouTube безрезультатно.В коде вы можете видеть, что я сделал две попытки добавить две метки.Не то чтобы никто не показывает.Элементы навигации работают правильно.Фон также устанавливается правильно.

import UIKit

class WelcomeController: UIViewController {

    // MARK: - Properties

    var pageTitle: UILabel!

    // MARK: - Init

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white

        let frameLabel:CGRect = CGRect(x: 20, y: 0, width: UIScreen.main.bounds.width - 20, height: 50)
        let label:UILabel = UILabel(frame: frameLabel)
        label.text = "This text is not showing up on the screen!!! his text is not showing up on the screen!!! his text is not showing up on the screen!!!"
        label.textColor = .black
        label.textAlignment = .center
        view.addSubview(label)

        configureUI()

        configurePageTitleLabel()

    }

    // MARK: - Selectors

    @objc func handleDismiss() {
        dismiss(animated: true, completion: nil)
    }

    // MARK: - Helper Functions

    func configureUI() {

        navigationController?.navigationBar.barTintColor = .blue
        navigationItem.title = "Welcome"
        let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
        navigationController?.navigationBar.titleTextAttributes = textAttributes

        navigationItem.leftBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "ic_menu_white_3x").withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(handleDismiss))

    }

    // MARK - Page Contents Functions

    func configurePageTitleLabel() {

        pageTitle = UILabel()
        pageTitle.text = "Welcome"
        pageTitle.textAlignment = .center
        pageTitle.textColor = .black
        let frameTitle:CGRect = CGRect(x: 20, y: 20, width: UIScreen.main.bounds.width - 20, height: 50)
        pageTitle.drawText(in: frameTitle)
        view.addSubview(pageTitle)
        view.backgroundColor = .gray

    }
}

1 Ответ

0 голосов
/ 05 апреля 2019

Значение y должно быть больше 64, т.е.20 строка состояния + 44 панель навигации.Кроме того, вам не нужны DrawText и рамка кадра.Простое добавление

pageTitle.frame = CGRect(x: 20, y: 200, width: UIScreen.main.bounds.width - 20, height: 50)

будет работать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...