I am trying to change the text color of DecimalRow. Neither the tintColor nor textColor attributes on cell.textField seem to do anything:
<<< DecimalRow(){
$0.tag = "final";
$0.useFormatterDuringInput = true
let formatter = CurrencyFormatter()
formatter.locale = .current
formatter.numberStyle = .currency
$0.formatter = formatter
}.cellSetup({ (cell, row) in
cell.textField.textColor = UIColor(red:0.15, green:0.55, blue:0.16, alpha:1.0)
cell.textField.tintColor = UIColor(red:0.15, green:0.55, blue:0.16, alpha:1.0)
})
Try with cellUpdate closure instead, it works, look at the picture below
<<< DecimalRow(){
$0.tag = "final";
$0.useFormatterDuringInput = true
let formatter = CurrencyFormatter()
formatter.locale = .current
formatter.numberStyle = .currency
$0.formatter = formatter
}.cellUpdate({ (cell, row) in
cell.textField.textColor = UIColor(red:0.15, green:0.55, blue:0.16, alpha:1.0)
cell.textField.tintColor = UIColor(red:0.15, green:0.55, blue:0.16, alpha:1.0)
})
I hope this helps you, best regards
Related
I want to make animation on a text, and need to have each letter separated.
This works :
let hero = document.querySelector('.hero');
let text = hero.textContent;
hero.textContent = '';
let letters = text.split('');
letters.forEach((letter) => {
let newSpan = document.createElement('span');
let newContent = document.createTextNode(letter);
newSpan.appendChild(newContent);
if (newSpan.textContent == ' ') {
newSpan.style.marginRight = '5px';
newSpan.style.marginLeft = '5px';
}
hero.appendChild(newSpan);
});
<div class="hero">My awesome sentence</div>
But I would like to use this in another context, so to turn it into a function.
This dosesn't works, message : sentenceDiv.appendChild is not a function
let spanifyText = (sentenceDiv) => {
let text = sentenceDiv.textContent;
sentenceDiv = '';
let letters = text.split('');
letters.forEach((letter) => {
let newSpan = document.createElement('span');
let newContent = document.createTextNode(letter);
newSpan.appendChild(newContent);
if (newSpan.textContent == ' ') {
newSpan.style.marginRight = '5px';
newSpan.style.marginLeft = '5px';
}
sentenceDiv.appendChild(newSpan);
});
};
let hero = document.querySelector('.hero');
spanifyText(hero);
<div class="hero">My awesome sentence</div>
It is certainly a newbie problem but cannot figure it out.
Any help please ?
Thanks in advance
Thanks for pointing out the problem !
Just modified html by adding a span with a class for the original text, then removing it at the end of the function. Code can certainly be improved but it does the job !
let spanifyText = (sentenceDiv) => {
let originalSpan = sentenceDiv.querySelector('.original-span');
let text = sentenceDiv.textContent;
let letters = text.split('');
letters.forEach((letter) => {
let newSpan = document.createElement('span');
let newContent = document.createTextNode(letter);
newSpan.appendChild(newContent);
if (newSpan.textContent == ' ') {
newSpan.style.marginRight = '5px';
newSpan.style.marginLeft = '5px';
}
sentenceDiv.appendChild(newSpan);
});
originalSpan.parentNode.removeChild(originalSpan);
};
let hero = document.querySelector('.hero');
spanifyText(hero);
<div class="hero"><span class="original-span">My Awesome Text</span></div>
We have created a clickable text in UITextView by using this code
var urlString = #"<a href=""https://www.google.com"" >Google</a>";
var documentAttributes = new NSAttributedStringDocumentAttributes { DocumentType = NSDocumentType.HTML };
NSError error = null;
var attributedString = new NSAttributedString(NSData.FromString(urlString, NSStringEncoding.UTF8), documentAttributes, ref error);
// Should really check the NSError before applying
MyTextView.AttributedText = attributedString;
but its showing by default blue color for the link and underlined text. We want to change the color for the text and also remove underline.
Please guide/help me to implement this.
You can change these properties just adding UIStringAttributeKey.ForegroundColor and UIStringAttributeKey.UnderlineStyl to your dictionary and set it to WeakLinkTextAttributes property
var key1 = UIStringAttributeKey.ForegroundColor;
var value1 = UIColor.Red;
var key2 = UIStringAttributeKey.UnderlineStyle;
var value2 = new NSNumber(0); // 0 without underline 1 with underline
var dict = new NSDictionary(key1, value1, key2, value2);
var urlString = #"<a href=""https://www.google.com"" >Google</a>";
var documentAttributes = new NSAttributedStringDocumentAttributes {
DocumentType = NSDocumentType.HTML };
NSError error = null;
var attributedString = new NSAttributedString(NSData.FromString(urlString, NSStringEncoding.UTF8), documentAttributes, ref error);
yourTextView.AttributedText = attributedString;
yourTextView.WeakLinkTextAttributes = dict;
I want to mark each CharacterStyle in the document by placing an achored text frame above each text/word. I am quite new to scripting in indesign, so any help is much appreciated.
Here is the expected output:
I found a solution to this, and for those who might encounter the same problem as me here is my code :
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
app.findGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.appliedCharacterStyle = style;
app.findGrepPreferences.findWhat = ".+";
var found_item = doc.findGrep();
var res_count = found_item.length;
if(res_count > 0){
var found_text = found_item[0].paragraphs.firstItem();
var insertion_character = (found_text.characters.lastItem().index);
var check_insertion_character = insertion_character + 1;
var alt_insertion_character = (found_text.characters.firstItem().index);
var the_story = found_text.parentStory;
try{
app.selection = the_story.insertionPoints[check_insertion_character];
app.selection = the_story.insertionPoints[alt_insertion_character];
}catch(err){
alert(err);
}
var the_anchored_frame = app.selection[0].textFrames.add({geometricBounds:["0","0",1,10],anchoredObjectSettings:{anchoredPosition: AnchorPosition.ABOVE_LINE, horizontalReferencePoint: AnchoredRelativeTo.ANCHOR_LOCATION, verticalReferencePoint: VerticallyRelativeTo.TOP_OF_LEADING}});
the_anchored_frame.contents = style;
// the_anchored_frame.appliedObjectStyle = real_anchor_style;
}
Cheers
i try to change the labelcolor, if the "date" in my detailTextLabel.text older then today..
// Configure the cell...
cell.textLabel?.textColor = UIColor.blueColor()
cell.detailTextLabel?.textColor = UIColor.darkGrayColor()
let item = frc.objectAtIndexPath(indexPath) as! Item
cell.textLabel?.text = item.name! + "-" + item.etage! + "-" + item.raum!
let note = item.date
cell.detailTextLabel!.text = "\(note!)"
if note == "01.04.2016 23:00" {
cell.detailTextLabel?.textColor = UIColor.redColor()
} else {
}
return cell
}
How can i do this? It works with a specific date but not with NSDate() or something like this. I go crazy!
big thx!
As pointed there you can make something like this:
...
let note = item.date
let now = NSDate()
if note.earlierDate(now).isEqualToDate(note) {
cell.detailTextLabel?.textColor = UIColor.redColor()
}
I want to change marker image in my MKPointAnnotation() and I have successfully changed my image but problem is that I have 2 marker points and I want to place ignitionon.png on point one and ignitionof.png on point two and my logic place ignitionon.png on both the points.
Code
if(self.doubelLocation) {
var pointOff = CLLocationCoordinate2D()
var pointOn = CLLocationCoordinate2D()
if(self.dateTime.count > 0) {
for(var i : Int = 0 ; i < self.dateTime.count ; i++) {
// print("Real status = \(self.dateTime[i])")
var fixTime = self.dateTime[i]
if(fixTime == self.dateTimeTwo) {
pointOff = CLLocationCoordinate2DMake(self.latt[i], self.lngg[i]);
print("pointOff = \(pointOff)")
//points.append(pointOf)
}
if(fixTime == self.dateTimeOne){
pointOn = CLLocationCoordinate2DMake(self.latt[i], self.lngg[i]);
print("pointOn = \(pointOn)")
//points.append(pointOf)
}
}
var points: [CLLocationCoordinate2D]
points = [pointOn, pointOff]
dispatch_async(dispatch_get_main_queue(), {
let geodesic = MKGeodesicPolyline(coordinates: &points[0], count: 2)
self.theMapView.addOverlay(geodesic)
let latDelta:CLLocationDegrees = 0.03
let lnggDelta:CLLocationDegrees = 0.03
UIView.animateWithDuration(1.5, animations: { () -> Void in
let span = MKCoordinateSpanMake(latDelta, lnggDelta)
let region1 = MKCoordinateRegion(center: points[0], span: span)
self.theMapView.setRegion(region1, animated: true)
self.ActivityIndicator.stopAnimating()
for(var i : Int = 0 ;i < points.count; i++){
var st = self.reportText[i]
// let theMarker = MKPointAnnotation()
//how to change marker color
//https://stackoverflow.com/questions/33532883/add-different-pin-color-with-mapkit-in-swift-2-1
let theMarker = MKPointAnnotation()
theMarker.coordinate = points[i]
// if(st == "IGNITION ON"){
if(i == 0){
theMarker.title = "Status : IGNITION OFF"
theMarker.subtitle = "\(self.locationOff)"
// theMarker.subtitle = "Date = , Reg#: "
self.theMapView.addAnnotation(theMarker)
let anView1:MKAnnotationView = MKAnnotationView()
anView1.annotation = theMarker
anView1.image = UIImage(named:"ignitionof")
anView1.canShowCallout = true
anView1.enabled = true
}
if(i == 1){
// theMarker = UIColor.greenColor()
theMarker.title = "Status : IGNITION ON"
theMarker.subtitle = "\(self.locationOn)"
// theMarker.subtitle = "Date = , Reg#: "
self.theMapView.addAnnotation(theMarker)
//how to change image of marker
//https://stackoverflow.com/questions/24467408/swift-add-mkannotationview-to-mkmapview
let anView:MKAnnotationView = MKAnnotationView()
anView.annotation = theMarker
anView.image = UIImage(named:"ignitionon")
anView.canShowCallout = true
anView.enabled = true
}
// }
}
})
})
}
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if (annotation is MKUserLocation) {
//if annotation is not an MKPointAnnotation (eg. MKUserLocation),
//return nil so map draws default view for it (eg. blue dot)...
return nil
}
let reuseId = "test"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView!.image = UIImage(named:"ignitionon")
anView!.canShowCallout = true
}
var anView1 = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView1 == nil {
anView1 = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView1!.image = UIImage(named:"ignitionof")
anView1!.canShowCallout = true
}
else {
//we are re-using a view, update its annotation reference...
anView!.annotation = annotation
}
return anView
}
I am following this Link:
Swift - Add MKAnnotationView To MKMapView
It's not the best way to handle multiple marker with different metadata.
You can't use mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) two times or more because in viewForAnnotation it is for only 1 view for each Point you have added in the stack.
Create a sub-class of MKPointAnnotation:
class CustomPointAnnotation: MKPointAnnotation {
var tag: String!
}
Create a Dictionary with all images:
var imagesPath : ["tag_1": "image_1.png", "tag_2": "image_2.jpg"]
Now in the delegate func, check Simply
if !(annotation is CustomPointAnnotation) {
return nil
}
and Handle the only one View you have:
let reuseId = "test"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
var customannotation = annotation as! CustomPointAnnotation
anView!.image = UIImage(named: imagesPath(customannotation.tag))
anView!.canShowCallout = true
}
An example to add a new Custom point is:
let aPoint = CustomPointAnnotation()
aPoint.coordinate = CLLocationCoordinate2DMake(40.730872, -73.003066)
aPoint.title = "Info1"
aPoint.subtitle = "Subtitle"
aPoint.tag = "tag_1"
mapView.addAnnotation(aPoint)