我在使用Cloud Firestore生成随机唯一ID时遇到问题.以前我使用实时数据库并生成一个我使用的随机字符串childByAutoID().key.
有没有办法为Cloud Firestore做类似的事情?
正如杰伊在评论中所说,这不是重复,因为我正在尝试生成一个随机字符串,我不是想要随机文档.
我有一个包含文本和图像的按钮,但我希望图像上有一个角半径.当我尝试将角半径应用于按钮时,它适用于我认为正确的整个按钮.如何将角半径设置为图像?
这是我的代码:
let titleButton = UIButton()
titleButton.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
titleButton.setTitle("display name", for: .normal)
titleButton.setImage(#imageLiteral(resourceName: "imgName"), for: .normal)
titleButton.layer.masksToBounds = true
titleButton.layer.cornerRadius = titleButton.frame.width / 2
self.navigationItem.titleView = titleButton
Run Code Online (Sandbox Code Playgroud) 我有一个UINavigationItem,我将它的titleView设置为UIView,它嵌入了UILabel和UIImageView.我正在尝试向视图添加UITapGestureRecognizer,但它似乎不起作用.有解决方案吗 此外,将gestureRecognizer添加到整个navigationBar不是一个选项,因为我有一个rightBarButtonItem并想要使用后退按钮.
这是我的代码:
func configureTitleView() {
guard let profile = profile else {
// Pop navController
return
}
let titleView = UIView()
titleView.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
let containerView = UIView()
containerView.translatesAutoresizingMaskIntoConstraints = false
titleView.addSubview(containerView)
let profileImageView = UIImageView()
profileImageView.translatesAutoresizingMaskIntoConstraints = false
profileImageView.contentMode = .scaleAspectFill
profileImageView.clipsToBounds = true
let imageURL = URL(string: profile!.firstProfilePicture!)
profileImageView.sd_setImage(with: imageURL)
containerView.addSubview(profileImageView)
profileImageView.leftAnchor.constraint(equalTo: containerView.leftAnchor).isActive = true
profileImageView.centerYAnchor.constraint(equalTo: containerView.centerYAnchor).isActive = true
profileImageView.widthAnchor.constraint(equalToConstant: 36).isActive = true
profileImageView.heightAnchor.constraint(equalToConstant: 36).isActive = true
profileImageView.layer.cornerRadius = 36 …Run Code Online (Sandbox Code Playgroud)