我想定制一个5星级的UIView,我也希望它能在故事板中呈现.所以我决定使用@IBDesignable和@IBInspectable.以下是我的代码.
import UIKit
@IBDesignable
class RatingView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setUpView()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setUpView()
}
func setUpView() {
let imageView = UIImageView(frame:CGRectMake(0, 0, 50,50))
imageView.image = UIImage(named: "star")
addSubview(imageView)
}
}
Run Code Online (Sandbox Code Playgroud)
然后在我的故事板中,我将UIView拉入我的画布,并将Custom类设置为我的自定义视图作为RatingView.编译器开始编译storyboard文件,我只是等待自定义视图在canvas中呈现.这是截图.

状态是"最新的",但视图尚未渲染.视图只是保持白色,我想看到的是我添加到父视图的图像.当我使用UILabel而不是UIImageView时,标签是在画布中渲染而不是UIImageView,我如何在画布中渲染可爱的星形图像.(Images.xcassets有star.png文件)

使用UILabel而不是UIImageView
func setUpView() {
let label = UILabel(frame: CGRectMake(0, 0, 50, 50))
label.text = "text"
addSubview(label)
}
Run Code Online (Sandbox Code Playgroud)
结果:

我知道之间的区别UIImage(named:String)和UIImage(contentsOfFile:String),我只是有超过保存到200MB图像Images.xcassets文件夹.我发现我的应用程序有超大的内存使用量(超过500 MB),所以我考虑使用UIImage(contentsOfFile:String)构造函数,因为它不会缓存图像.我搜索了很多,并找到了以下解决方案.
myImageView.image = UIImage(contentsOfFile: NSBundle.mainBundle().pathForResource("my_img_name",ofType:"png"))
Run Code Online (Sandbox Code Playgroud)
Howerver,当它运行时,应用程序崩溃了.以下是可能与我的问题相关的链接:访问资产目录pathForResource
Apple Watch 可以用吗AVFoundation?更具体地说,可以AVAudioPlayer并且AVAudioRecorder工作吗?
我正在尝试制作一个应用程序,让您可以将声音录制到 Apple Watch 并让它使用音频播放器播放。谢谢
avfoundation avaudioplayer avaudiorecorder apple-watch watchkit
我Gradle在我的Android项目中使用,并且我在文件中添加了一些依赖项.build.gradle出于某些原因,我想指向我的一个依赖项的最新提交.例如:
dependencies {
...
compile 'com.github.ozodrukh:CircularReveal:1.1.0@aar'
}
Run Code Online (Sandbox Code Playgroud)
我指的是CircularReveal版本是1.1.0 @ aar,我知道它目前已修复了一些bug但尚未发布它.如何在Gradle中指定一个提交?我知道一些基础知识Cocoapods,它可以是像这样做:
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => '082f8319af'
Run Code Online (Sandbox Code Playgroud)
可以在Gradle中完成吗?任何帮助将不胜感激.
我正在介绍UIImagePickerController一个UITabBarController.
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .Camera
imagePicker.allowsEditing = false
imagePicker.showsCameraControls = false
presentViewController(imagePicker, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我明确设置showsCameraControls为false将我的自定义叠加视图放在相机顶部.但为什么底部有黑色空间?有什么帮助?

在iOS 8.3中,Apple更新了一堆表情符号,我想知道是否可以更快地将所有表情符号放入数组中.
如:
let emojiArrays = ["","",...] or plist or something else.
Run Code Online (Sandbox Code Playgroud) 在这里,我有一个简单的片段,使用我定义的UIView的简单动画.
UIView.animateWithDuration(0.1) { [weak self] in
self?.popOverView.center = gesture.locationInView(self?.view)
}
Run Code Online (Sandbox Code Playgroud)
这里[弱自我]是为了避免引用循环,我也使用尾随闭包来简单地代码.Howerver,编译器对此不满意并给我错误的消息.
Cannot invoke 'animateWithDuration' with an argument list of type '(FloatLiteralConvertible, () -> () -> $T2)'
Run Code Online (Sandbox Code Playgroud)
$ T2代表什么?奇怪的是,当闭包体中有两个或多个语句时,它会正确编译.
UIView.animateWithDuration(0.1) { [weak self] in
println()
self?.popOverView.center = gesture.locationInView(self?.view)
}
Run Code Online (Sandbox Code Playgroud)
我知道如果闭包体中只有一个语句,它会自动返回.
@IBAction func popOverRadarChart(sender: UIButton) {
let popOverViewController = ResultTwoPopoverViewController(nibName: "ResultTwoPopoverViewController", bundle: nil)
popOverViewController.modalPresentationStyle = UIModalPresentationStyle.FormSheet
popOverViewController.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
popOverViewController.preferredContentSize = CGSizeMake(540, 622)
popOverViewController.view.layer.cornerRadius = 0.0
popOverViewController.view.layer.masksToBounds = true
presentViewController(popOverViewController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
如果我可以将这四个角半径移到0.0.
doc说这thumbnailURL是项目缩略图图像的本地文件URL.
如何使房地产thumbnailURL支持的Web网址是什么?
有没有办法判断目前是否有UIAlertView实例显示?因为可以UIAlertView在同一窗口级别显示多个.
if ([self isAlertViewShowing]) {
// do not show UIAlertView again.
} else {
// show your UIAlertView.
}
Run Code Online (Sandbox Code Playgroud)
希望有一种叫做isAlertViewShowing或其他的方法.
swift ×5
ios ×4
android ×1
apple-watch ×1
avfoundation ×1
camera ×1
closures ×1
emoji ×1
git ×1
github ×1
gradle ×1
ibdesignable ×1
ios9 ×1
objective-c ×1
uialertview ×1
uiimage ×1
uiview ×1
watchkit ×1