我想在Swift中获得UIColor的RGB值:
let swiftColor = UIColor(red: 1, green: 165/255, blue: 0, alpha: 1)
println("RGB Value is:");
println(swiftColor.getRGB()); <<<<<< How to do that ?
Run Code Online (Sandbox Code Playgroud)
在Java中我会这样做:
Color cnew = new Color();
int iColor = cnew.rgb(1, 165/255, 0);
System.out.println(iColor);
Run Code Online (Sandbox Code Playgroud)
我应该如何获得这个价值?
我有以下代码来显示没有箭头的popoverview(对话框),它工作正常.唯一的问题是,对话框显示在左上角(IPad).我想将视图置于屏幕中心.
在我的下面的代码中要更改或添加什么?:
func show_help(){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("Help") as! UIViewController
controller.modalPresentationStyle = UIModalPresentationStyle.popover
let popoverPresentationController = controller.popoverPresentationController
// result is an optional (but should not be nil if modalPresentationStyle is popover)
if let _popoverPresentationController = popoverPresentationController {
// set the view from which to pop up
_popoverPresentationController.sourceView = self.view;
_popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirection.allZeros;
// present (id iPhone it is a modal automatic full screen)
self.presentViewController(controller, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
额外的信息
在我的视图中,链接到我的viewcontroller我设置了这样的优先大小:
override …Run Code Online (Sandbox Code Playgroud) 我按照说明创建了一个带Gradle支持的简单IntelliJ项目,并且没有创建src文件夹(我想这是任何Java项目的基础) https://www.jetbrains.com/help/idea/getting-started -with-gradle.html
我没有src文件夹.我无法添加新课程.
在没有gradle的情况下做同样的事情我有src文件夹.
更新 添加一个名为"src"的模块,但是我有一个名为src的模块和一个名为src的文件夹.但这是一个黑客.刚刚以200美元买了IntelliJ,我希望这可以用更专业的方式解决:-)
我想覆盖CGFloat的'='运算符,如下面的尝试:
func = (inout left: CGFloat, right: Float) {
left=CGFloat(right)
}
Run Code Online (Sandbox Code Playgroud)
所以我可以做以下事情:
var A:CGFloat=1
var B:Float=2
A=B
Run Code Online (Sandbox Code Playgroud)
可以这样做吗?我收到了错误Explicitly discard the result of the closure by assigning to '_'
随着android kitkat 4.4.2版本是针对writeaccess实施的新google策略,到目前为止我还不明白.
我在其他应用中阅读了很多关于这个问题的内容.他们得到"EACCES权限被拒绝".我的应用程序需要编写/解压缩zipfile,也写入sqlite数据库.
如何通过Android版本4.4.2 KITKAT解决此EACCES权限被拒绝的问题?
如何通过通知发送数字和字符串...
let mynumber=1;
let mytext="mytext";
NSNotificationCenter.defaultCenter().postNotificationName("refresh", object: ?????????????);
Run Code Online (Sandbox Code Playgroud)
并在接收器中接收值?
func refreshList(notification: NSNotification){
let receivednumber=??????????
let receivedString=?????????
}
Run Code Online (Sandbox Code Playgroud) 我尝试解压缩只包含一个项目(超过100MB)的大型zip文件,并希望在解压缩过程中显示进度.
我找到了解决方案,根据解压缩的文件数量可以确定进度,但在我的情况下,我只有一个大文件.所以我猜它必须由解压缩的字节数决定?
实际上我使用SSZipArchive与以下代码工作正常:
var myZipFile:NSString="/Users/user/Library/Developer/CoreSimulator/Devices/mydevice/ziptest/testzip.zip";
var DestPath:NSString="/Users/user/Library/Developer/CoreSimulator/Devices/mydevice/ziptest/";
let unZipped = SSZipArchive.unzipFileAtPath(myZipFile as! String, toDestination: DestPath as! String);
Run Code Online (Sandbox Code Playgroud)
我找不到解决方法.
有人有样品的提示,样品或链接吗?
更新: 以下代码看起来会按预期工作,但只有一个文件被解压缩时,处理程序将只被调用一次(在解压缩结束时):
func unzipFile(sZipFile: String, toDest: String){
SSZipArchive.unzipFileAtPath(sZipFile, toDestination: toDest, progressHandler: {
(entry, zipInfo, readByte, totalByte) -> Void in
println("readByte : \(readByte)") // <- This will be only called once, at the end of unzipping. My 500MB Zipfile holds only one file.
println("totalByte : \(totalByte)")
//Asynchrone task
dispatch_async(dispatch_get_main_queue()) {
println("readByte : \(readByte)")
println("totalByte : \(totalByte)")
//Change progress value
}
}, completionHandler: …Run Code Online (Sandbox Code Playgroud) 我设法绘制了一个矩形:-)但我不知道如何画一个圆形的矩形.有人可以帮助我使用以下代码如何围绕矩形?:
let canvas = UIGraphicsGetCurrentContext()
rec = CGRectMake(0, 0, 40, 40);
//var maskPath = UIBezierPath(roundedRect: rec, byRoundingCorners: .BottomLeft | .BottomRight, cornerRadii: CGSize(width: 3, height: 3))
CGContextAddRect(canvas, rec);
CGContextFillPath(canvas);
Run Code Online (Sandbox Code Playgroud) 在过去(旧版xcode)我在编辑器的右上角有一个加号来添加一个标签.然后在新选项卡中我可以单击第二个文件,我在2个选项卡中打开了2个文件.我的加号消失了(我猜我上次更新).
如何在Xcode 6.4(6E35b)中回滚此+按钮或如何使用选项卡式编辑器?
有很多解决方案可以找出应用程序运行的设备.
iOS:如何确定Swift中当前的iPhone /设备型号?
但是在模拟器中运行,我们只能检测到它是模拟器,而不是什么类型的模拟器(iphone5,6,6s等)
我们如何根据模拟器的devicetype测试不同的逻辑?或者我如何检测代码中模拟的设备?