Comments (2)
Hey @mbalex99, I've updated the podspec to 2.1.0
. You can now style the UI using UIAppearance, like this:
[UITextField appearanceWhenContainedIn:[CLTokenInputView class], nil].font = [UIFont italicSystemFontOfSize:17];
Thanks!
from cltokeninputview.
hello
i made this class but i can not change the font size
import Foundation
import CLTokenInputView
class ContactTokenView: CLTokenInputView, UITableViewDelegate, UITableViewDataSource, CLTokenInputViewDelegate {
private var contacts = IContact
private var filteredContacts = IContact
var selectedContacts = NSMutableArray()
private var contactsTableView: UITableView!
private let tableViewRowHeight: CGFloat = 60.0
private let tableViewMaxRows = 4
var showGenericParticipant = false
var heightConstraint: NSLayoutConstraint!
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.backgroundColor = UIColor.whiteColor()
let color = UIColor.lightGrayColor().colorWithAlphaComponent(0.4)
self.backgroundColor = UIColor.whiteColor()
self.layer.cornerRadius = 5
self.layer.borderColor = color.CGColor
self.layer.borderWidth = 1
self.delegate = self
contactsTableView = UITableView()
contactsTableView.registerClass(ContactItem.self, forCellReuseIdentifier: "ContactItem")
contactsTableView.delegate = self
contactsTableView.dataSource = self
contactsTableView.frame = CGRectMake(0, 0, 0, 0)
contactsTableView.rowHeight = tableViewRowHeight
ContactModel.findAll(){ contacts, error in
if error == nil {
self.contacts = contacts
}
}
}
override func layoutSubviews() {
super.layoutSubviews()
for constraint in self.constraints {
if constraint.firstAttribute == NSLayoutAttribute.Height {
heightConstraint = constraint
}
}
if heightConstraint == nil {
heightConstraint = NSLayoutConstraint(item:self, attribute:NSLayoutAttribute.Height, relatedBy:NSLayoutRelation.Equal, toItem:nil, attribute:NSLayoutAttribute.NotAnAttribute, multiplier:1.0, constant:44)
}
self.window?.addSubview(contactsTableView)
}
// UITableViewDataSource
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return filteredContacts.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("ContactItem", forIndexPath:indexPath) as! ContactItem
let contact = self.filteredContacts[indexPath.row]
cell.backgroundColor = UIColor.blackColor()
cell.contactName.numberOfLines = 0
cell.contactName.text = contact.getName()
if contact.getRole() == ContactRole.ROLE_PARTICIPANT {
cell.contactIcon.image = UIImage(named: "ic_contact")
} else if contact.getRole() == ContactRole.ROLE_GROUP {
cell.contactIcon.image = UIImage(named: "ic_contact_group")
} else if contact.isGeneric() {
cell.contactIcon.image = UIImage(named: "ic_contact_generic")
} else {
cell.contactIcon.image = UIImage(named: "ic_contact_provider")
}
return cell
}
// UITableViewDelegate
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.contactsTableView.deselectRowAtIndexPath(indexPath, animated: true)
let contact = self.filteredContacts[indexPath.row]
let token = ContactToken(displayText: contact.getName(), contact:contact)
if self.editing {
self.addToken(token);
}
}
// CLTokenInputViewDelegate
func tokenInputView(view: CLTokenInputView, didChangeText text: String?) {
if text!.isEmpty {
self.filteredContacts.removeAll(keepCapacity: true)
} else {
self.filteredContacts = contacts.filter() {
let contact = $0 as IContact
if showGenericParticipant {
return contact.getSearchableString().containsString(text!)
}
return (!contact.isGeneric()) && contact.getSearchableString().lowercaseString.containsString(text!.lowercaseString)
}
}
let x = self.frame.minX
let y = self.frame.maxY
let w = self.frame.width
var h:CGFloat = tableViewRowHeight * CGFloat(tableViewMaxRows)
if filteredContacts.count < tableViewMaxRows {
h = tableViewRowHeight * CGFloat(filteredContacts.count)
}
contactsTableView.frame = CGRectMake(x, y, w, h)
self.contactsTableView.reloadData()
}
func tokenInputView(view: CLTokenInputView, didAddToken token: CLToken) {
let contactToken = token as! ContactToken
self.selectedContacts.addObject(contactToken.contact)
}
func tokenInputView(view: CLTokenInputView, didRemoveToken token: CLToken) {
let contactToken = token as! ContactToken
self.selectedContacts.removeObject(contactToken.contact)
}
func tokenInputView(view: CLTokenInputView, didChangeHeightTo height: CGFloat) {
if let constraint = heightConstraint {
constraint.constant = height
} else {
let frame = self.frame
self.frame = CGRectMake(frame.minX, frame.minY, frame.width, height)
}
}
// Token class
class ContactToken : CLToken {
var contact: IContact
init(displayText: String, contact: IContact!) {
self.contact = contact
let truncate = displayText.truncate(18, trailing: "...")
super.init(displayText: truncate, context: nil)
}
}
}
extension String {
/// Truncates the string to length number of characters and
/// appends optional trailing string if longer
func truncate(length: Int, trailing: String? = nil) -> String {
if self.characters.count > length {
return self.substringToIndex(self.startIndex.advancedBy(length)) + (trailing ?? "")
} else {
return self
}
}
}
from cltokeninputview.
Related Issues (20)
- InputAccessoryView Implementation
- Right To Left language issues HOT 2
- Would be helpful to have read/write access to textfield text HOT 2
- change delimiter (feature request)
- [Feature] Coloring each token and get focus HOT 2
- Ability to customize textColor for textField HOT 1
- Ability to customize font for fieldLabel and textField HOT 2
- Ability to programmatically become first responder HOT 1
- KeyboardAppearance does not applied to CLTokenView
- Separate enter & backspace behavior when highlighted
- Incorrect height of TokenInputView HOT 1
- Limit of tokens HOT 3
- Incorrect keyboardType
- height problem when token removed HOT 1
- CLTokenInput does not increase it height HOT 2
- Limit height or change direction scroll??? HOT 2
- change back color when not selected
- Active text input overlaps previous token
- v2.4.0 in CocoaPods
- Supporting accessibility - Larger text in ios
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cltokeninputview.