I'm trying to align a UIImageView to the left of a UITableViewCell.
I thought I have to use something like
cell.imageView.image = [UIImageView CGFloat....];
but as it turns out that it doesn't work.
Does anyone have an idea?
This might work:
cell.imageView.contentMode = UIViewContentModeLeft;
Related
UIButton *openButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
openButton.frame = CGRectMake((main.frame.size.width/2)-15, (main.frame.size.height/2)+75, 30, 30);
openButton.backgroundColor = [UIColor clearColor];
openButton.layer.cornerRadius = 16;
openButton.layer.borderWidth = 2;
openButton.layer.borderColor = themeColor.CGColor;
[openButton addTarget:self action:#selector(wasDragged:withEvent:)
forControlEvents:UIControlEventTouchDragInside];
[openButton addTarget:self action:#selector(showMenu)
forControlEvents:UIControlEventTouchDownRepeat];
This is my open button's code that was already implemented into the mod menu but I really want to change it to a sample image instead of a circle. I tried changing it to an UIImage but I am not sure how to do it properly since i am new to coding.
Please try this:
yourBtn.setImage(UIImage(named: "ImgName"), for: .normal)
Please convert to objective c. setImage is a property of UIButton for image setting.
It may helps you. Thank you
A part from question:
i really want to change it to a sample image instead of a circle
seems like a problem with:
openButton.layer.cornerRadius = 16;
Removing this line should give you actual image on button.
I have a NSTableCellView that has a simple NSTextField and an NSImageCell.
NSTableCellView *cell = [tableView makeViewWithIdentifier:#"List" owner:self];
cell.textField.stringValue = name;
cell.imageView.image = [NSImage imageNamed:#"image1.png"]; (or image 2,3, etc)
Later, when I select a row from the table, I'd like to be able to see the name of the image. If I preload the image from IB, I can use:
NSTableColumn *column = [self.tableView tableColumnWithIdentifier:#"List"];
NSCell *cell = [column dataCellForRow:row];
NSLog(#"TableView image:%#",cell.image.name);
This shows the IB Name - e.g. NSEveryWhere
But when I load the images at run time, the same statement results in (null).
Any help would be appreciated. Please note that this is for OS/X - however, for future use, I would appreciate iOS ideas as well. Thanks
i think you should use cell.imageView.image.name rather than logging cell.image.name
I want to make the tabbar transparent and leave the icons still there. So that when you look at it the icons on the tabbar look like they are their by themselves. Whats the code for me to do this? Right now this is the code i have
UIImage* tabBarBackground = [UIImage imageNamed:#""];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#""]];
Try this code
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = CGRectMake(0.0, 0, self.view.bounds.size.width, 48);
UIView *trans_view = [[UIView alloc] initWithFrame:frame];
[trans_view setBackgroundColor:[[UIColor alloc] initWithRed:0.0
green:0.0
blue:0.0
alpha:0.5]];//you can change alpha value also
[tabBar1 insertSubview:trans_view atIndex:0];//tabBar1 = your tabbar reference
[trans_view release];
}
this link also will help you
The easiest way to make a tab bar transparent is by setting the tab bar background image to a transparent image in the interface builder.
You can get a transparent png image whose height and width is equal to the tab bar's from the net.
Note: By changing the alpha value, you actually end up dimming the tab bar's icons as well. Make sure this is what you want, otherwise using a transparent background image is a better option.
I've a grouped UITableView which has been resized and rounded. I would like to place a view BEHIND this table.I've tried:
[self.tableView addSubview:backgroundView];
[self.tableView sendSubviewToBack:backgroundView];
but it didn't work. This is what I obtain:
I would like to have the background in place of the black space.
Any idea?
How about [self.tableView setBackgroundView:backgroundView];?
Bear with me I'm a beginner. I just ran into this problem and I found two solutions. In my case, I was using a UITableView object.
To begin, add the background image into your app's directory. I put mine in "Supporting Files"
You can add the image as a UIColor object:
...
[resultsTable setBackGroundColor:setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"background.jpg"]]];
...
The problem with this method is that it will repeat your background image because it's treating it as a pattern.
The better way:
// Create a string to store the path location of your image, otherwise you would have to provide an exact path name
NSString *backPath = [[NSBundle mainBundle] pathForResource:#"background"
ofType:#"jpg"];
// Create a UIImage Object to store the image.
UIImage *bgImage = [[UIImage alloc ] initWithContentsOfFile:backPath];
// Create a UIImageView which the TableView
UIImageView *bgView = [[UIImageView alloc]initWithImage:bgImage];
// Set your TableView's background property, it takes a UIView Obj.
[resultsTable setBackgroundView: bgView];
.....
I want to know how to center a UIImage to UIButton. I am using the setImage method of UIButton to place the UIImage..
You can use the contentMode Property:
button.imageView.contentMode = UIViewContentModeCenter;
Remove the text from the UIButton before setting the content mode
Sometimes you might have the wrong content alignment. Make sure they are both in the center with :
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;