小编use*_*052的帖子

在UIAlertController中将图像添加到UIAlertAction

我已经看过UIAlertControllers的几个屏幕截图,在行的左边有一个图像,但我没有在文档中看到它.视觉的一个例子是http://imgur.com/SISBvjB 这是我现在为我的控制器提供的代码:

UIAlertController * view =   [UIAlertController
                                 alertControllerWithTitle:@"My Title"
                                 message:@"Select you Choice"
                                 preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction* ok = [UIAlertAction
                         actionWithTitle:@"OK"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                          }];
    [view addAction:ok];
    [self presentViewController:view animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

ios uialertcontroller

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

Swift中的日期到毫秒和更新

我以UTC的当前时间,并将其置于nanaoseconds,然后我需要花费纳秒并回到当地时间的日期.我能够把时间缩短到纳秒,然后回到日期字符串,但是当我从字符串到日期时,时间会变得复杂.

    //Date to milliseconds
     func currentTimeInMiliseconds() -> Int! {
            let currentDate = NSDate()
            let dateFormatter = DateFormatter()
            dateFormatter.dateFormat = format
            dateFormatter.timeZone = NSTimeZone(name: "UTC") as TimeZone!
            let date = dateFormatter.date(from: dateFormatter.string(from: currentDate as Date))
            let nowDouble = date!.timeIntervalSince1970
            return Int(nowDouble*1000)
        }

    //Milliseconds to date
    extension Int {
        func dateFromMilliseconds(format:String) -> Date {
            let date : NSDate! = NSDate(timeIntervalSince1970:Double(self) / 1000.0)
            let dateFormatter = DateFormatter()
            dateFormatter.dateFormat = format
            dateFormatter.timeZone = TimeZone.current
            let timeStamp = dateFormatter.string(from: date as Date)

let formatter = …
Run Code Online (Sandbox Code Playgroud)

time date ios swift

40
推荐指数
4
解决办法
7万
查看次数

Xcode 11 Beta 5不显示Swift 5.1

我已经从Apple网站下载了XCode 11,并且尝试将代码升级到Swift 5.1,但是XCode却没有提供满足该要求的选项。另外,我看不到iOS 13模拟器可用。我以前从未遇到过这个问题,所以我想念什么?我的操作系统已更新为MacOS Catalina

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

xcode ios swift

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

'substring(to :)'已弃用:请使用字符串切片下标和'partial range upto'运算符

如何将以下代码更新为新版本的swift:

self.areaCodeLael.text! = localNumber.substring(to: localNumber.index(localNumber.startIndex, offsetBy: 3))
Run Code Online (Sandbox Code Playgroud)

我曾尝试过这篇文章,但我无法正确 使用如何在Swift 4中使用字符串切片下标?

我调整了原始代码,localNumber[..<3]但得到了:

无法使用类型为"PartialRangeUpTo"的索引下标"String"类型的值

substring swift swift4

10
推荐指数
2
解决办法
5706
查看次数

LargeTitles UIScrollView不支持实现_scrollViewWillEndDraggingWithVelocity的多个观察者:targetContentOffset

我在我的应用程序中使用以下代码实现了大型标题:

if #available(iOS 11.0, *) {
            navigationController?.navigationBar.prefersLargeTitles = true
            navigationItem.largeTitleDisplayMode = .always
        } else {
            // Fallback on earlier versions
        }
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if scrollView.contentOffset.y <= 0 {
        if #available(iOS 11.0, *) {
            self.navigationItem.largeTitleDisplayMode = .always
        } else {
            // Fallback on earlier versions
        }
    } else {
        if #available(iOS 11.0, *) {
            self.navigationItem.largeTitleDisplayMode = .never
        } else {
            // Fallback on earlier versions
        }
    }
    self.navigationController?.navigationBar.setNeedsLayout()
    self.view.setNeedsLayout()
    UIView.animate(withDuration: 0.01, animations: {
        self.navigationController?.navigationBar.layoutIfNeeded()
        self.view.layoutIfNeeded()
    })
} …
Run Code Online (Sandbox Code Playgroud)

crash tabbar uiscrollview navigationbar swift

7
推荐指数
2
解决办法
1837
查看次数

红蜘蛛代表没有被召唤

变量不是nil,我有一个很好的连接,url是正确的,但没有调用委托方法.我也正在实现WebSocketDelegate

 let socket = WebSocket(url: NSURL(string: "UrlHere:port/")!)
            socket.delegate = self;
            socket.connect()
            if socket.isConnected {
                print("websocket is connected")
            }

    func websocketDidConnect(ws: WebSocket) {
        print("websocket is connected")
    }

    func websocketDidDisconnect(ws: WebSocket, error: NSError?) {
        if let e = error {
            print("websocket is disconnected: \(e.localizedDescription)")
        } else {
            print("websocket disconnected")
        }
    }

    func websocketDidReceiveMessage(ws: WebSocket, text: String) {
        print("Received text: \(text)")
    }

    func websocketDidReceiveData(ws: WebSocket, data: NSData) {
        print("Received data: \(data.length)")
    }

    func websocketDidReceivePong(socket: WebSocket) {
        print("Got pong!")
    }
Run Code Online (Sandbox Code Playgroud)

sockets delegates ios swift

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

UIAlertAction带有不同颜色的按钮文字

我正在尝试创建一个UIAlertAction,第一个按钮为黑色文本,第二个按钮为蓝色.如果我改变色调然后全部变黑,但是没有它我不能将第一个按钮改为黑色.以下是我的代码:

let alert = UIAlertController(title: "", message: "", preferredStyle: .actionSheet)
// alert.view.tintColor = UIColor.black

alert.addAction(UIAlertAction(title: "First", style: .cancel, handler: nil))

alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))

self.present(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

uiactionsheet ios swift uialertaction

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

Bypasses Apple Captive Network Assistant在iOS 7中登录

由于iOS 7阻止了http://www.apple.com/library/test/success.html的欺骗,我正在寻找阻止强制网络助手登录页面的另一种方法.由于Apple有设备检查1-> m网站,我无法确定所有网站都被阻止.

如果无法阻止它,我会打开将其更改为带有接受按钮的网页,如术语页面,但我找不到一种方法来做到这一点.

iphone networking captivenetwork ios7

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

将音频更改为蓝牙设备并返回

当用户选择操作表上的选项时,我试图将音频输出更改为设备。这是代码,当我选择将音频发送到设备时,下次不会出现蓝牙。:

for input in AVAudioSession.sharedInstance().availableInputs!{
            if input.portType == AVAudioSessionPortBluetoothA2DP || input.portType == AVAudioSessionPortBluetoothHFP || input.portType == AVAudioSessionPortBluetoothLE{
                let bluetooth = UIAlertAction(title: input.portName, style: .default, handler: {
                    (alert: UIAlertAction!) -> Void in
                    let audioSession = AVAudioSession.sharedInstance()
                    do {
                        try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: AVAudioSessionCategoryOptions.allowBluetooth)
                        try audioSession.setActive(true)
                    } catch {
                        fatalError("Error Setting Up bluetooth output \(input.portName)")
                    }


                })

                bluetooth.setValue(UIImage(named:"bluetooth.png"), forKey: "image")
                optionMenu.addAction(bluetooth)
            }

let iphomeOutput = UIAlertAction(title: "iPhone", style: .default, handler: {
                (alert: UIAlertAction!) -> Void in
                let audioSession = AVAudioSession.sharedInstance()
                do {
                    do …
Run Code Online (Sandbox Code Playgroud)

audio bluetooth ios avaudiosession swift

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