小编Nir*_*avS的帖子

Swift 3.0:将服务器UTC时间转换为本地时间,反之亦然

我想将服务器UTC时间转换为本地时间,反之亦然.这是我的代码..

var isTimeFromServer = true
var time:String!
var period:String!
let timeString = "6:59 AM" //Current UTC time

if isTimeFromServer {

    let index = timeString.index(timeString.startIndex, offsetBy: 5)
    let twelve = timeString.substring(to: index)

    var dateString:String!

    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "H:mm"
    let date12 = dateFormatter.date(from: twelve)!

    dateFormatter.dateFormat = "h:mm a"
    let date22 = dateFormatter.string(from: date12)

    //print(date22)
    dateString = date22
    //print("dateString=\(dateString)")

    time = dateString.components(separatedBy: " ")[0]
    period = dateString.components(separatedBy: " ")[1]

}
else {
    time = timeString.components(separatedBy: " ")[0]
    period = timeString.components(separatedBy: …
Run Code Online (Sandbox Code Playgroud)

nsdate nsdateformatter nsdatecomponents swift

32
推荐指数
4
解决办法
5万
查看次数

如何设置 UIButton 图像,该图像是带边框的圆形

如何设置 UIButton 图像,该图像是带边框的圆形我编写了相关代码但图像没有以正确的圆形显示..这是我的代码..

    btnMyProfile.setImage(UIImage(named: "MyDefaultImg.png"), for: .normal)
    btnMyProfile.imageView?.contentMode = .scaleAspectFit
    btnMyProfile.imageView?.layer.cornerRadius = (btnMyProfile.imageView?.frame.width)! / 2
    btnMyProfile.imageView?.layer.borderColor = UIColor.blue.cgColor
    btnMyProfile.imageView?.layer.borderWidth = 2.0
Run Code Online (Sandbox Code Playgroud)

我的 o/p 看起来像这样.. 在此处输入图片说明

但我需要这样.. 在此处输入图片说明

我能做些什么来实现我想要的输出?

uibutton uiimage ios swift swift3

1
推荐指数
1
解决办法
3974
查看次数

我需要使用UIImageView设置UITableViewCell Dynamic Height,With Multiple dynamic label

我需要UITableViewCell根据它的内容设置动态高度.

这是我的演示图片:

在此输入图像描述

在这个标签中有动态内容所以根据标签内容,我的单元格高度应该改变..

我得到了约束错误.在这个单元格中,有两个UILabel可用,并且都具有动态内容大小.(我已经使用只有一个标签的自动调整大小的单元格进行了演示.)但是在这个单元格中有两个标签.所以错误是xcode建议我给Y POS或Height标签,但我已经设置了顶级约束.(标签线设置为0的4个侧面约束)但是它仍然失败.我也尝试使用此代码

self.tableView.estimatedRowHeight = 250.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
Run Code Online (Sandbox Code Playgroud)

这是我的演示代码

uitableview uilabel ios swift

-1
推荐指数
1
解决办法
1174
查看次数