(记录)ios自定义toast

网友投稿 313 2022-08-22

(记录)ios自定义toast

func showMsgView(localizableString: String){ DispatchQueue.main.async { if let l = self.msgLabel { l.removeFromSuperview() } let txt = NSLocalizedString(localizableString, comment: "Default") let cgSize = CGSize(width: SCREEN_WIDTH * 0.8, height: SCREEN_HEIGHT) let textSize = NSString(string: txt).boundingRect(with: cgSize, options: [NSStringDrawingOptions.truncatesLastVisibleLine , NSStringDrawingOptions.usesFontLeading , NSStringDrawingOptions.usesLineFragmentOrigin], attributes: [NSFontAttributeName : UIFont.systemFont(ofSize: 16.0)], context: nil) let textRect = CGRect(x: (SCREEN_WIDTH - textSize.width) / 2.0 - 5.0, y:SCREEN_HEIGHT - 50.0 - textSize.height / 2.0 - 5.0 , width: textSize.width + 10.0, height: textSize.height + 10.0) let label:UILabel = UILabel.init(frame: textRect) label.text = txt label.textColor = self.thoastTxColor label.font = UIFont.systemFont(ofSize: 16.0) label.backgroundColor = self.thoastBgColor label.numberOfLines = 0 label.alpha = 1 label.textAlignment = .center label.layer.cornerRadius = 5 label.layer.masksToBounds = true self.view.addSubview(label) self.msgLabel = label UIView.animate(withDuration: 3.5, animations: { label.alpha = 0 }) } }

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:python究竟要不要使用多线程(python多线程菜鸟教程)
下一篇:arcgis for js 4.X 鼠标悬停弹出气泡
相关文章

 发表评论

暂时没有评论,来抢沙发吧~