Tag: 集中

居中使用Swift以编程方式alignmentUIView中的标签和图像

我在一个应用程序工作,并遇到了一个问题,我似乎无法解决。 我正在制作一个与其中的标签和图像uiview。 内容需要在视图中居中。 问题是标签将保存不同长度的文本,并且视图本身将根据使用的位置而具有不同的宽度。 这是它应该看起来如何: 这里有更长的文字: 正如你所看到的,左侧应该有一个标签,中间有一个标签,右侧有另一个标签,尽pipe文本的长度可能不同,但它们都居中。 这是我迄今为止的代码。 如果可能,我需要以编程方式进行此操作。 我运行一个方法来创buildbutton取决于一个值。 func cost(cost:Int){ costView = UIView() costView?.setTranslatesAutoresizingMaskIntoConstraints(false) self.costView?.clipsToBounds = true self.addSubview(costView!) self.costLabel.frame = CGRectMake(0, 0, 60, self.bounds.size.height) self.costLabel.textAlignment = NSTextAlignment.Right self.costLabel.textColor = UIColor.whiteColor() self.costLabel.font = Services.exoFontWithSize(16) self.costLabel.text = String(cost) costView?.addSubview(costLabel) self.costBrainImageView = UIImageView(frame: CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height)) self.costBrainImageView?.image = Graphics.maskImageNamed("CommonMediumBrain", color: UIColor.whiteColor()) self.costBrainImageView?.contentMode = UIViewContentMode.ScaleAspectFill costView?.addSubview(costBrainImageView!) […]

有没有办法以编程方式将iOS设备的相机对焦设置为无限?

我正在创build一个应用程序来locking摄像机焦点以进行video录制。 我想locking焦点到无穷无需用户手动调整焦点。 这可能吗? 谢谢!