How i can change CCLabelBMFont text color.
highScoreLabel = [CCLabelBMFont labelWithString:highScore fntFile:#"markerFelt.fnt"];
With the color property, for example:
highScoreLabel.color = ccc3(240, 40, 40);
This would only work well if the original color was white.
Related
I am coding my app using Xamarin, but I can translate any swift/objective-C responses.
I have a WKWebView that I using to display data with LoadHtmlString(). I want to change the background color of the UIToolbar that is displayed above the keyboard when a user focuses an input field. Right now, the button text color and background color are both white, so the buttons aren't visible.
I can change the button text color by using UIBarButtonItem.Appearance.TintColor = UIColor.White;, but this will also change the text color of the buttons in my UINavigationBar. I would rather leave the text white, and change the background color of the UIToolbar.
I can slightly modify the background color using UIToolbar.Appearance.BackgroundColor = UIColor.Red;, but this just adds a subtle tint of the color to the UIToolbar, and doesn't actually make the toolbar dark enough for the white text to be visible.
Here is my complete code for setting up my Appearance defaults:
UIColor lightColor = UIColor.White;
UIColor themeColor = UIColor.Red;
UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, false);
UINavigationBar.Appearance.BarStyle = UIBarStyle.Black;
UINavigationBar.Appearance.BarTintColor = themeColor;
UINavigationBar.Appearance.Translucent = false;
UINavigationBar.Appearance.TintColor = lightColor;
UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes()
{
TextColor = lightColor
});
UIStringAttributes navBarAttributes = new UIStringAttributes();
navBarAttributes.ForegroundColor = lightColor;
UINavigationBar.Appearance.TitleTextAttributes = navBarAttributes;
UITabBar.Appearance.BarTintColor = themeColor;
UITabBar.Appearance.TintColor = lightColor;
UIToolbar.Appearance.BarTintColor = themeColor;
UIToolbar.Appearance.TintColor = lightColor;
UIBarButtonItem.Appearance.TintColor = lightColor;
UIButton.AppearanceWhenContainedIn(typeof(UINavigationBar)).TintColor = lightColor;
UIToolbar.Appearance.BackgroundColor = themeColor;
Is there a way to change the WKWebView's toolbar background color without having to retheme my entire app?
If I can't change the background color of the toolbar, I am open to changing the button text color when displayed in a WKWebView. I have tried adding the following code, but nothing seems to work.
//Using green to see if the code is working.
UIBarButtonItem.AppearanceWhenContainedIn(typeof(WKWebView)).TintColor = UIColor.Green;
UIBarButtonItem.AppearanceWhenContainedIn(typeof(MyViewController)).TintColor = UIColor.Green;
You can have a try with custom UIToolBar to change its background color by an image :
public class MyToolBar: UIToolbar
{
public override void Draw(CGRect rect)
{
base.Draw(rect);
CGContext c = UIGraphics.GetCurrentContext();
UIImage image = new UIImage("background.png");
//here set image to be background color
c.DrawImage(rect, image.CGImage);
}
}
And toolbar will only used for where you used , can not affecting other toolbar in app.
MyToolBar myToolBar = new MyToolBar();
myToolBar.Frame = new CoreGraphics.CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width, 50);
UIBarButtonItem doneItem = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, doneClickMethod);
List<UIBarButtonItem> list = new List<UIBarButtonItem>();
list.Add(doneItem);
myToolBar.Items = list.ToArray();
MySearchBar.InputAccessoryView = myToolBar;
My sprite image is black, I want to change this color to whatever I want.
The code I'm using:
var sprite = SKSpriteNode(imageNamed: "layer1-0\(random(1..<4))")
ceilingPieces.append(sprite)
sprite.setScale(0.5)
sprite.position = CGPointMake(900, 335)
sprite.color = UIColor.purpleColor()
sprite.colorBlendFactor = 1.0
self.addChild(sprite)
The image stays black, but I want it to be purple.
Thanks!
Toby.
A black tile image isn't going to be able to tint. You're working with filters here so it doesn't matter what you put over it, it's still going to look black. Get a white or mostly white image and you'll see that it will work as expected. Again, tint color is multiplied by the original color to get to the end result.
If you were instead working with
var sprite = SKSpriteNode(color: UIColor.blackColor(), size: CGSizeMake(100, 100))
you could then change the color but it would be a blend, it would simply be changing the color with
sprite.color = UIColor.purpleColor()
I have a custom UIButton that has some text I am setting on it dynamically.
The problem:
If the text gets too large, it will cover up a white arrow that is on the button's image located on the far right here:
When that text gets too large, that white arrow is covered, which I need to avoid.
Example:
Current code:
[self.filterButton setTitle:#"All" forState:UIControlStateNormal];
self.filterButton.titleLabel.adjustsFontSizeToFitWidth = YES;
self.filterButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
self.filterButton.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
[self.filterButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
Some approaches I have tried:
Setting the titleText frame to be %0.85 of the buttons frame.
Current code
Tried to code it to where the frame cuts off at a certain point (of the titleText)
Thanks for any guidance
Have you tried setting the titleEdgeInsets rather than the contentEdgeInsets?
I have a sprite and I set its color and then I want to set it back to the old color(Default color) how can I do it
here a simple code
sprite = [[CCSprite alloc] initWithFile:#"zero.png"];
sprite.color = ccc3(255, 223, 0);
....
How to set it back to the default color
sprite.color = ???????
or I have to find out the default color by find that old color RGB code?
sprite.color = ccWHITE;
And I have to add some text here so SO will accept the answer. :)
ccWHITE is the same as ccc3(255, 255, 255)
I have a UI button that I'd like to put two labels on it, similar to how a cell has a title text and detail text.
I'd like the button to have a larger font for the main text, and have smaller detail text under that.
Is this possible? I've tried to put multiple lines on a button, but I need to have different text sizes for each line, so setting the lineBreakMode and numberOfLines of the titleLabel doesn't really quite work.
Here's the code we finally used. Assistance from John Wang.
Thanks to everyone for the suggestions!
// Formats a label to add to a button. Supports multiline buttons
// Parameters:
// button - the button to add the label to
// height - height of the label. usual value is 44
// offset - the offset from the top of the button
// labelText - the text for the label
// color - color of the text
// formatAsBold - YES = bold NO = normal weight
// tagNumber - tag for the label
- (void) formatLabelForButton: (UIButton *) button withHeight: (double) height andVerticalOffset: (double) offset andText: (NSString *) labelText withFontSize: (double) fontSize withFontColor: (UIColor *) color andBoldFont:(BOOL) formatAsBold withTag: (NSInteger) tagNumber {
// Get width of button
double buttonWidth= button.frame.size.width;
// Initialize buttonLabel
UILabel *buttonLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, offset, buttonWidth, height)];
// Set font size and weight of label
if (formatAsBold) {
buttonLabel.font = [UIFont boldSystemFontOfSize:fontSize];
}
else {
buttonLabel.font = [UIFont systemFontOfSize:fontSize];
}
// set font color of label
buttonLabel.textColor = color;
// Set background color, text, tag, and font
buttonLabel.backgroundColor = [UIColor clearColor];
buttonLabel.text = labelText;
buttonLabel.tag = tagNumber;
// Center label
buttonLabel.textAlignment = UITextAlignmentCenter;
// Add label to button
[button addSubview:buttonLabel];
[buttonLabel autorelease];
} // End formatLabelForButton
A trick I would recommend is putting a UIButton with a transparent interior on top of UILabels. I've used this trick before and, although it may present some problems in terms of maintenance and i18n, it works like a charm.
Here is a 5 minutes sample using the suggestion above.
Given more time, you can make a better label with round corners.
you should be able to add subviews to it. Since everything is a view, everything can potentially have subviews.
I would subclass it and put the labels on it within the subclass, Then you can extend properties for text and subtext to change their values.
Not saying it can 100% work. But off the top of my head. UIView can have SubViews