-1

我想在导航栏上制作日历
就像在图片上
输入图片描述一样

但我不知道如何在日历图像上贴标签
请帮助我
谢谢

4

1 回答 1

1

使用以下代码在导航栏中添加图像和标签:

let button =  UIButton(type: .custom)
        button.setImage(UIImage(named: "calenderImage"), for: .normal)
        button.addTarget(self, action: Selector(("buttonAction")), for: .touchUpInside)
        button.frame = CGRect(x: 0, y: 0, width: 53, height: 31) 
        let label = UILabel(frame: CGRect(x: 3, y: 5, width: 50, height: 20))// set position of label
        label.font = UIFont(name: "Arial-BoldMT", size: 16)// add font and size of label
        label.text = "your date number"
        label.textAlignment = .center
        label.textColor = UIColor.black
        label.backgroundColor =   UIColor.clear
        button.addSubview(label)
        let barButton = UIBarButtonItem(customView: button)
        self.navigationItem.rightBarButtonItem = barButton
于 2018-12-26T12:23:16.807 回答