I'm trying to add gradient to a text in UILabel in table view cell in cellForRowAtIndexPath method, with the following code:
cell.cellLabel.textColor = UIColor(patternImage: UIImage(named: "gradientText"))
where "gradientText" is a png file of a gradient required & textColor is the UILabel in the cell. But the text color remains to be the default color. Can I achieve it without using any third party code.
Reference link
extension UILabel {
func setTextColorToGradient(image: UIImage) {
UIGraphicsBeginImageContext(frame.size)
image.draw(in: bounds)
let myGradient = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.textColor = UIColor(patternImage: myGradient!)
}
}
You can use like this :
cell.cellLabel.setTextColorToGradient(image: UIImage(named: "gradientText")!)
Related
As in subject, I am wondering if right now in React Native is an option to change color of inactive TabBar icon from default gray to custom color? With or without using react-native-vector-icons
I found solution, but your icon should be in "inactive" color. To achieve this go to RTCTabBarItem.m and change first line in method setIcon:
- (void)setIcon:(UIImage *)icon
{
_icon = [icon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
if (_icon && _systemIcon != NSNotFound) {
_systemIcon = NSNotFound;
UITabBarItem *oldItem = _barItem;
_barItem = [UITabBarItem new];
_barItem.title = oldItem.title;
_barItem.imageInsets = oldItem.imageInsets;
_barItem.selectedImage = oldItem.selectedImage;
_barItem.badgeValue = oldItem.badgeValue;
}
self.barItem.image = _icon;
}
Then in all TabBarIOS.Item add field selectedIcon with the same url as in icon (that's no matter), set tintColor of TabBarIOS to "active" color and that's all! TabBar will be rendered with default icon color (inactive), and active icon will be in tintColor. I think that TabBar field renderAsOriginal should do this, but it not works. After all I found this solution on github https://github.com/facebook/react-native/issues/3083
Another solution (may not works in some cases):
in xCode find file RCTTabBar.m (cmd + shift + f)
find - (instancetype)initWithFrame:(CGRect)frame
add before return self:
[[UIView appearanceWhenContainedIn: [UITabBar class], nil] setTintColor: [UIColor redColor]];
[[UITabBar appearance] setSelectedImageTintColor: [UIColor greenColor]];
Restart Simulator/Device
In code redColor is color of inactive buttons, and greenColor is color of active button. For more details checkout this Unselected UITabBar color?
Edit: I found great tool if you want convert RGB to UIColor http://uicolor.xyz/
I am trying to finish up a custom cell for my tables using monotouch.dialog, and have nearly everything sorted out, except for my cell's detail text label colour.
I am overriding GetCell to customise my EntryElement cell like this:
public class CustomStyledEntryElementPlain : MonoTouch.Dialog.EntryElement
{
public CustomStyledEntryElementPlain (string _caption, string _value) : base(string.Empty,string.Empty,string.Empty,false)
{
KeyboardType = UIKeyboardType.Default;
Value = _value;
ReturnKeyType = UIReturnKeyType.Done;
Caption = _caption;
}
public override UITableViewCell GetCell(UITableView tableView) {
var cell = base.GetCell(tableView);
cell.BackgroundColor = Resources.XDarkGrayColor;
cell.TextLabel.TextColor = Resources.XWhiteColor;
cell.BackgroundView = new UIView (RectangleF.Empty);
cell.DetailTextLabel.TextColor = UIColor.White; //this line causes the error
return cell;
}
}
I then create the elements like so:
new CustomSection ("Testing"){
new CustomStyledEntryElementPlain("Test","Test1"),
new CustomStyledEntryElementPlain("Test","Test2")
},
However, on displaying the table, I get the error: "System.NullReferenceException has been thrown Object reference not set to an instance of an object"
I could have sworn when I initially prototyped this that I had the DetailTextLabel text color working! Commenting out the change of course results in my table and cell displaying just fine, albeit with black text (which I want to change to white!)
Has anyone got any idea as to why I am getting this?
The DetailTextLabel property in the UITableViewCell is only available if the Cell has a UITableViewCellStyle that supports it. From the UITableViewCell documentation for the DetailTextLabel property:
UITableViewCell automatically creates the secondary (detail) label if the cell is created with a MonoTouch.UIKit.UITableViewCellStyle that supports a detail label.
If the cell's style doesn't support a detail label, this property returns null.
Check the documentation for UITableViewCellStyle to find out which styles support this property.
I have a list of color representing a color sequence. I want to apply the new color sequence to the piechart data.
private final int CASPIAN_COLOR_COUNTS = 8;
public void setPieChartColor(PieChart chart, List<String> colors) {
chart.getData().get(i); // for debug to get the node name (.data)
/**
* Set Pie color
*/
int i = 0;
for (String color : colors) {
final Node node = chart.lookup(".data" + i);
node.getStyleClass().remove("default-color" + (i % CASPIAN_COLOR_COUNTS));
node.getStyleClass().add(color);
i++;
}
but all chart data take Only one color from Caspian color.
You can achieve custom pie colors in code using a method such as:
private void applyCustomColorSequence(
ObservableList<PieChart.Data> pieChartData,
String... pieColors) {
int i = 0;
for (PieChart.Data data : pieChartData) {
data.getNode().setStyle(
"-fx-pie-color: " + pieColors[i % pieColors.length] + ";"
);
i++;
}
}
Note that the method must be applied after the chart has been shown on an active scene (otherwise the data.getNode() call will return null).
Here is some sample code which uses it.
You can accomplish the same effect using css stylesheets.
For example a css stylesheet containing the following style definitions will change the default colors of a pie chart when the stylesheet is applied against a given chart.
.default-color0.chart-pie { -fx-pie-color: #ffd700; }
.default-color1.chart-pie { -fx-pie-color: #ffa500; }
.default-color2.chart-pie { -fx-pie-color: #860061; }
.default-color3.chart-pie { -fx-pie-color: #adff2f; }
.default-color4.chart-pie { -fx-pie-color: #ff5700; }
For an example of the stylesheet based approach: see the "Setting Colors of a Pie Chart" section of the Styling Charts with CSS tutorial.
The stylesheet approach has an advantage that the styles are separated from the code. It has the disadvantage that the colors are must be set the time the stylesheet are created rather than at runtime and the color sequence is restricted to a fixed number of colors (8).
In general, the stylesheet approach is recommended for most applications.
The css styles might not work if your values are negative. This might be a bug but I had to convert my values to positive values for the styles to work. When the values were negative all pies were white in color.
I have a UICollectionView that displays images. My images are size 114x133 but for some reason the actual UICollectionVewCell is bigger than this (I can see this because I set the cell background to red). Because of this the view can display only 2 images and there is a huge gap between the two. I am implementing the following
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
UIImage* img = [UIImage imageNamed:#"thumbnail_frame.png"];
return img.size;
}
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(1, 1, 1, 1);
}
I am creating the cell's contentview programmatically (i.e init imageView etc).
I face the same problem in a different view where I am creating the whole view programmatically. There I do:
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumInteritemSpacing=10;
flowLayout.minimumLineSpacing= 30;
flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
if(collectionView != nil) {
[collectionView removeFromSuperview];
}
CGRect frm= CGRectMake(45, 80, 250, 230);
collectionView = [[UICollectionView alloc] initWithFrame:frm collectionViewLayout:flowLayout];//(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flowLayout];
collectionView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
collectionView.clipsToBounds = YES;
collectionView.layer.cornerRadius = 10.0;
collectionView.dataSource = self;
collectionView.delegate = self;
[collectionView registerClass:[YourPicCollectionViewCell class] forCellWithReuseIdentifier:#"YourPicCell"];
Again there is either a big gap between two images, or if I make the width smaller, there are 3 images but the right-most one is half-visible.
I tinkered with spacing but it doesn't seem to work. What could be the problem?
I think instead of resizing the cell.. you should try resizing the collection view. Make sure that the collection view has just enough width to hold 2 items in a row. This is because if the collection view has more width than the cells, then then will stick to the extreme right and left. If it's too short, then only one cell will be displayed at the centre (Assuming that you are trying to keep 2 cells in a row).
The reason that one of your cell was half visible is that the collection view had more width than its super view.
So doing the following would help you get what you want..
Frame your collection view such that its less than its super view and should be equal to (numberOfCells X width) + ((numberOfCells-1) X cellGap).
If it's a custom collection view cell try adding constraints to the imageView such that the image sticks to the cells edges.
The ComboBox text color is white even though I've set it to black in my theme. The text color of TextField is black as supposed to. How come the ComboBox text color isn't black?
The theme:
fgColor=FFFFFF
bgColor=000000
sel#fgColor=FFFFFF
sel#bgColor=EE8207
ComboBox.fgColor=000000
ComboBox.bgColor=FFFFFF
ComboBox.sel#fgColor=000000
ComboBox.sel#bgColor=FFFFFF
TextField.fgColor=000000
TextField.bgColor=FFFFFF
TextField.sel#fgColor=000000
TextField.sel#bgColor=FFFFFF
You can change the text color like this
Style selStyle = UIManager.getInstance().getComponentSelectedStyle("ComboBoxItem");
selStyle.setFgColor(0x00AF00); // Selected Item will be in green color
UIManager.getInstance().setComponentSelectedStyle("ComboBoxItem", selStyle);
Style unSelStyle = UIManager.getInstance().getComponentStyle("ComboBoxItem");
unSelStyle.setFgColor(0x000000); // Selected Item will be in black color
UIManager.getInstance().setComponentStyle("ComboBoxItem", unSelStyle);
This will work out!!
You should use hexColors: "0x000000" or "0xffffff"
You can also set the color in your app using following methods.
lwuit uses int's to set a color, to calculate the int use the following function.
public static int colorStringToInt(String hexColor) {
int color;
try {
color = Integer.parseInt(hexColor.substring(2), 16);
return color;
} catch (Exception ex) {
ex.printStackTrace();
return -1;//no negative colors
}
}
set the color like this.
int color = AppUtils.colorStringToInt("0xffffff");//white
if (color != -1) {
b.getStyle().setFgColor(color, true);
}
you can use like this,
ComboBoxItem.fgColor=000000
ComboBoxItem.sel#fgColor=ffffff
Are you using ResourceEdit. If u r not using means use the ResourceEdit and create the theme.