小编las*_*302的帖子

在Swift中使用其他参数上传多个图像

现在,我一直只通过下面给出的代码将一个图像上传到服务器端脚本的服务器上.现在我有一个数组UIImage,我想知道如何使用它UIImageJPEGRepresentation(myImageView.image!, 0.1)来发布UIImageView数组中的所有图像?

func uploadImage()
{
    let postPictureUrl = NSURL(string: "http://www.23look.com/merchant/verify")
    let request = NSMutableURLRequest(URL: postPictureUrl!)
    request.HTTPMethod="POST"

    let param=[
        "mer_name" : shopNameUITF.text!,
        "mer_tel" : shopTelephoneUITF.text!,
        "mer_address" : shopAddressUITF.text!,
        "lat" : "39.6892",
        "lng" : "115.9239",
        "token": KeychainWrapper.stringForKey("tokenValue")!,
        "mer_type": "smalll"
    ]

    let abc =  KeychainWrapper.stringForKey("tokenValue")!

    let boundary = generateBoundaryString()

    request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

    let imageData = UIImageJPEGRepresentation(myImageView.image!, 0.1)

    if imageData==nil { print("image data is nil"); return }

    request.HTTPBody = createBodyWithParameters(param, filePathKey: "mer_license", imageDataKey: imageData!, boundary: boundary)

    let …
Run Code Online (Sandbox Code Playgroud)

http-post uiimage ios swift

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

如何在 Swift 中使 UICollection 视图的背景透明而不使其中的单元格透明

我有一个集合视图,当然我也有单元格。如果在属性检查器中我将集合视图的 alpha 更改为 0,其中的单元格也会变得透明。有没有办法使集合视图的背景透明,以便它后面的图像可见?

ios uicollectionview uicollectionviewcell uicollectionviewlayout swift

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

在Swift中更改UIAlertController上的一个或特定按钮的颜色

我有一个UIController的操作表类型,显示两个项目,第一个是"从App退出",另一个是"取消".我想将显示"从应用程序注销"的按钮的字体颜色更改为红色,并将"取消"按钮保留为默认颜色.我怎样才能做到这一点?以下是我的代码:

let cancelActionSheetButton = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { 
    (cancelSelected) -> Void in
    print("Cancel Selected")
}

let logoutActionSheet = UIAlertController(title:"Logout", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)

let logoutActionSheetButton = UIAlertAction(title: "Logout from App", style: UIAlertActionStyle.Default) { 
    (logoutSelected) -> Void in
}

logoutActionSheet.addAction(logoutActionSheetButton)
logoutActionSheet.addAction(cancelActionSheetButton)

self.presentViewController(logoutActionSheet, animated: true, completion:nil)
Run Code Online (Sandbox Code Playgroud)

ios swift uialertcontroller

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

iOS Swift:在显示警报确认消息的函数中返回“Bool”

我正在创建一个返回布尔值的函数。但是 Swift 向我展示了错误:

预期返回“Bool”的函数中缺少返回值

我的函数不直接返回“布尔”,它有一些条件,比如如果用户点击“确定”按钮,那么它应该返回真,如果“取消”则返回假。有人可以告诉我如何解决这个问题吗?请参阅以下代码以供参考:

func showConfirmationAlert(title: String!, message: String!) -> Bool {
    dispatch_async(dispatch_get_main_queue(), {
        let alertController=UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
        let okButton=UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default) { (okSelected) -> Void in
            return true
        }
        let cancelButton=UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (cancelSelected) -> Void in
            return false
        }
        alertController.addAction(okButton)
        alertController.addAction(cancelButton)
        if self.presentedViewController == nil {
            self.presentViewController(alertController, animated: true, completion: nil)
        }
    })
}
Run Code Online (Sandbox Code Playgroud)

ios swift uialertcontroller

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