gpt4 book ai didi

ios - 在 iOS 中实现 - Android MultiAutoCompleteTextView 与 Whatsapp 中的自定义标记器 [附图片]

转载 作者:可可西里 更新时间:2023-11-01 00:58:05 24 4
gpt4 key购买 nike

我想为 @ 创建自定义标记器,就像在 WhatsApp 功能中一样,当您打开组并键入 @ 时,会出现一个显示 friend 列表的弹出窗口,您可以从中选择一个列表。

我想展示这样的东西:

enter image description here

最佳答案

我之前完成的一些演示代码练习。

Demo Slide Up Like @

Github post

希望对您有所帮助。

import UIKit

class ViewController: UIViewController {

@IBOutlet var txtSearch : UITextField!
@IBOutlet var tblUserData : UITableView!
var myArrayOfDict: NSMutableArray = []

override func viewDidLoad() {
super.viewDidLoad()

myArrayOfDict = [["UserName": "Hasya", "UserID": "1", "UserImage": "1.png"],["UserName": "Demo", "UserID": "2", "UserImage": "2.png"],["UserName": "Hasya & Hasya", "UserID": "3", "UserImage": "3.png"],["UserName": "Demo User", "UserID": "4", "UserImage": "4.png"]]

tblUserData.layer.borderColor = UIColor.blueColor().CGColor
tblUserData.layer.borderWidth = 1.0
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return myArrayOfDict.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{

let cell : CustomCell! = tableView.dequeueReusableCellWithIdentifier("CustomCell", forIndexPath: indexPath) as! CustomCell

cell.imgUser.layer.cornerRadius = cell.imgUser.frame.size.height/2

let strImageName : String = (myArrayOfDict.objectAtIndex(indexPath.row).valueForKey("UserImage") as? String)!

cell.imgUser.image = UIImage(named: (strImageName))

cell.lblName.text = myArrayOfDict.objectAtIndex(indexPath.row).valueForKey("UserName") as? String


return cell
}


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{


let str : String = (myArrayOfDict.objectAtIndex(indexPath.row).valueForKey("UserName") as? String)!

txtSearch.text = txtSearch.text! + str
// String(format:"@", myArrayOfDict.objectAtIndex(indexPath.row).valueForKey("UserName") as? String)

UIView.animateWithDuration(0.5) { () -> Void in

var frameOftblUserData : CGRect = self.tblUserData.frame
frameOftblUserData.origin.y = 264
frameOftblUserData.size.height = 0
self.tblUserData.frame = frameOftblUserData

}


}

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

print(string)

if string.hasPrefix("@")
{
print("YES")

UIView.animateWithDuration(0.5) { () -> Void in

var frameOftblUserData : CGRect = self.tblUserData.frame
frameOftblUserData.origin.y = 132
frameOftblUserData.size.height = 132
self.tblUserData.frame = frameOftblUserData

}

}
else
{
print("NO")

UIView.animateWithDuration(0.5) { () -> Void in

var frameOftblUserData : CGRect = self.tblUserData.frame
frameOftblUserData.origin.y = 264
frameOftblUserData.size.height = 0
self.tblUserData.frame = frameOftblUserData

}

}

return true;
}


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}

enter image description here

关于ios - 在 iOS 中实现 - Android MultiAutoCompleteTextView 与 Whatsapp 中的自定义标记器 [附图片],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40465686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com