我知道UITextView默认可以检测到URL,但是我怎样才能检测到#tatata(#)?
它不需要在键入时检测主题标签,但随后viewDidLoad文本设置在UITextView,所以我想检测主题标签作为颜色或什么.
我一直在使用ActiveLabel,但这只是用于UILabel,我需要具有的滚动功能UITextView.
在我的应用程序中,我正在使用ActiveLabelfram Github.
在这种情况下,我的标签不会显示UILabel中间的文本.如果我使用普通的UILabel它可以正常工作,但是当它设置为ActiveLabel时,它会像这样.

(图像在运行时拍摄)
我认为这是以某种方式使用对齐的代码:
/// add line break mode
private func addLineBreak(attrString: NSAttributedString) -> NSMutableAttributedString {
let mutAttrString = NSMutableAttributedString(attributedString: attrString)
var range = NSRange(location: 0, length: 0)
var attributes = mutAttrString.attributesAtIndex(0, effectiveRange: &range)
let paragraphStyle = attributes[NSParagraphStyleAttributeName] as? NSMutableParagraphStyle ?? NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = NSLineBreakMode.ByWordWrapping
if let lineSpacing = lineSpacing {
paragraphStyle.lineSpacing = CGFloat(lineSpacing)
}
attributes[NSParagraphStyleAttributeName] = paragraphStyle
mutAttrString.setAttributes(attributes, range: range)
return mutAttrString
}
Run Code Online (Sandbox Code Playgroud)
(图片取自故事板)
我现在使用此代码在按钮水龙头上旋转瓶子:
@IBAction func spinButton(sender: AnyObject) {
let rotateView = CABasicAnimation()
let randonAngle = arc4random_uniform(360) + 720
rotateView.fromValue = 0
rotateView.toValue = Float(randonAngle) * Float(M_PI) / 180.0
rotateView.duration = 3
rotateView.delegate = self
rotateView.repeatCount = 0
rotateView.removedOnCompletion = false
rotateView.fillMode = kCAFillModeForwards
rotateView.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
bottleImageView.layer.addAnimation(rotateView, forKey: "transform.rotation.z")
}
Run Code Online (Sandbox Code Playgroud)
但是如何使用手势旋转按钮?因此,我移动手指越硬/越快,瓶子旋转的速度就越快
我试图调整单元格高度调整大小以适应UILabel文本,但它不工作..
var mySize = CGFloat()
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! cellView
cell.myLabel.text = self.items[indexPath.item]
cell.myLabel.bounds.size.height = self.mySize
cell.backgroundColor = UIColor.yellowColor()
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
// handle tap events
print("You selected cell #\(indexPath.item)!")
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
func heightForLabel(text:String, font:UIFont, width:CGFloat) -> CGFloat
{
let label:UILabel = UILabel(frame: CGRectMake(0, 0, width, CGFloat.max))
label.numberOfLines = 0 …Run Code Online (Sandbox Code Playgroud) 所以,目前我用它来压缩视频:
func compressVideo(inputURL: NSURL, outputURL: NSURL, handler:(session: AVAssetExportSession)-> Void)
{
let urlAsset = AVURLAsset(URL: inputURL, options: nil)
let exportSession = AVAssetExportSession(asset: urlAsset, presetName: AVAssetExportPresetMediumQuality)
exportSession!.outputURL = outputURL
exportSession!.outputFileType = AVFileTypeQuickTimeMovie
exportSession!.shouldOptimizeForNetworkUse = true
exportSession!.exportAsynchronouslyWithCompletionHandler { () -> Void in
handler(session: exportSession!)
}
}
Run Code Online (Sandbox Code Playgroud)
当我在2秒内录制视频时,大小为4.3 MB,当我在6秒内录制视频时,文件大小为9,3 MB.
任何减小尺寸的提示?
我如何以编程方式调整字体大小,使文本适合UILabel,而不调整大小UILabel?
我已经设定了这个:
imageCell?.imageText.adjustsFontSizeToFitWidth = true
Run Code Online (Sandbox Code Playgroud)
同样在我设置的故事板中Line Breaks: Word Wrap,Autoshrink: Minimum Font Size: 1和Lines: 0.
这是整个标签文字:
Æ❤️❤️mzbdjdis#Svsuzi.#vdb#%<<,#hs.ClcldbsD.Cmcøclco
但是整个文本仍没有在标签中显示.我没有在我的应用程序中使用AutoLayout.有什么建议?
如何设置残留在人物UILabel的UITextView?
我已经为UITextField,但同样的代码不起作用..
这是我尝试过的:
func textView(textView: UITextView, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool
{
if string == ""
{
if plainTextView.text!.characters.count == 0
{
charCount = 0
countLabel.text = String(format: "%i Characters Left", maxLength - charCount)
return false
}
charCount = (plainTextView.text!.characters.count - 1)
countLabel.text = String(format: "%i Characters Left", maxLength - charCount)
return true
}
else
{
charCount = (plainTextView.text!.characters.count + 1)
countLabel.text = String(format: "%i Characters Left", maxLength - charCount)
if …Run Code Online (Sandbox Code Playgroud) 所以我正在创建一款纸牌游戏Ring of Fire.我存储了这样的图像:
var picture:[UIImage] = [
UIImage(named: "Card2")!,
UIImage(named: "Card3")!,
UIImage(named: "Card4")!,
UIImage(named: "Card5")!,
UIImage(named: "Card6")!,
UIImage(named: "Card7")!,
UIImage(named: "Card8")!,
UIImage(named: "Card9")!,
UIImage(named: "Card10")!,
UIImage(named: "CardJack")!,
UIImage(named: "CardQueen")!,
UIImage(named: "CardKing")!,
UIImage(named: "CardAce")!,
]
Run Code Online (Sandbox Code Playgroud)
每张卡片都有当前卡片下方显示的文字:
var name:String = ""
var files = ["Velg en som må drikke", // 2
"Drikk selv", // 3
"Alle jenter må drikke", // 4
"Tommelen", // 5
"Alle gutter må drikke", // 6
"Pek på himmelen", // 7
"Drikkepartner", // 8
"Rim", // 9
"Kategori", …Run Code Online (Sandbox Code Playgroud)