I was using PSButtonCell's for links but three individual ones took up too much space so I'm trying to create a custom cell with three buttons in one row; basically like 3 floating icons.
I've got some code for creating a tableview with icons, but currently I do not know how to space them properly (all the icons currently overlap), and I have no idea how I should go about adding tap listeners to the views. Does this look like something I could modify to do what I want? If not does anyone have a better solution they could provide for me? thanks a lot heres my code for the icons
- (id)tableView:(id)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 1) {
UIView *headerView = [[UIView alloc] initWithFrame:(CGRect){{0, 0}, {320, kHeaderHeight}}];
headerView.backgroundColor = UIColor.clearColor;
headerView.clipsToBounds = YES;
// icon
UIImage *bugicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/Bug.png", kSelfBundlePath]];
UIImageView *bugiconView = [[UIImageView alloc] initWithImage:bugicon];
bugiconView.frame = (CGRect){{0, 21}, bugiconView.frame.size};
// bugiconView.center = (CGPoint){headerView.center.x, bugiconView.center.y};
bugiconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[headerView addSubview:bugiconView];
UIImage *payicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/Paypal.png", kSelfBundlePath]];
UIImageView *payiconView = [[UIImageView alloc] initWithImage:payicon];
payiconView.frame = (CGRect){{0, 21}, payiconView.frame.size};
// payiconView.center = (CGPoint){headerView.center.x, payiconView.center.y};
payiconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[headerView addSubview:payiconView];
UIImage *btcicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/bitcoin.png", kSelfBundlePath]];
UIImageView *btciconView = [[UIImageView alloc] initWithImage:btcicon];
btciconView.frame = (CGRect){{0, 21}, btciconView.frame.size};
// btciconView.center = (CGPoint){headerView.center.x, btciconView.center.y};
btciconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[headerView addSubview:btciconView];
You're adding all the subview is in same position. All UIView frame start from same 'x' position '0'. You need to change 2nd and 3rd frame x positon . ( Change your CGRect 'X' position) for second and third UIView.
bugiconView.frame = (CGRect){{0, 21}, bugiconView.frame.size};
payiconView.frame = (CGRect){{0, 21}, payiconView.frame.size};
btciconView.frame = (CGRect){{0, 21}, btciconView.frame.size};
Hope it helps...
Related
I need to hide previews image, how can i fix it?
https://i.stack.imgur.com/sjlvD.gif
//create inner tab bar item
self.innerTabBarItem = [[UIButton alloc] init];
[self addSubview:self.innerTabBarItem];
self.innerTabBarItem.userInteractionEnabled = NO;//allows for clicks to pass through to the button below
self.innerTabBarItem.translatesAutoresizingMaskIntoConstraints = NO;
//create selected icon
self.selectedImageView = [[UIImageView alloc] initWithImage:selectedImage];
self.selectedImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.innerTabBarItem addSubview:self.selectedImageView];
//create unselected icon
self.unselectedImageView = [[UIImageView alloc] initWithImage:unselectedImage];
self.unselectedImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.innerTabBarItem addSubview:self.unselectedImageView];
Actually i want to do animation in objective.I have added list of imageview(subclassed) to view and stored all imageView in Array as following
CustomImageView *imageView = [[CustomImageView alloc]init];
imageView.tag = index;
imageView._x = (i%4)*150;
imageView._y = int(i/4)*150;
imageView.vx = 0;
imageView.vy = 0;
imageView.dragging = false;
imageView.frame = CGRectMake(imageView._x, imageView._y, imageView._width, imageView._height);
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapGesture:)];
tapGesture1.numberOfTapsRequired = 1;
[tapGesture1 setDelegate:self];
[imageView addGestureRecognizer:tapGesture1];
[self.view addSubview:imageView];
[imageViewsArray addObject:imageView];
can we access to change values of specific imageView property(subclass property) by following code
UIImageView * imageView = [imageViewsArray objectAtIndex:tag];
imageView.dragging = true;
imageView.vx = 0;
imageView.vy = 0;
Hmmm... um yes, it would work I think.
Not quite sure what you're trying to do here (especially given your x/y being based on the index), but in general instead of creating a CustomImageView for each image (which you would then have to insert into the view hierarchy), perhaps load the images (i.e., a UIImage) into your array instead and THEN swap them into your CustomImageView.
I'm running into a problem trying to perform a certain effect on iOS with tableviews...I know this can be done with normal UIViewControllers, but can't seem to pull it off with UITableViewControllers.
The effect is showing a clear background image behind a tableview and and as the user scrolls down the tableview, the background blurs. No problem getting that to happen.
The issue I'm having is that using a UITableViewController, I can only seem to have 1 ImageView behind the TableView and to create the blurring effect, the extension i am using will require 2 image views, one of which is the blurred image and has it's opacity set to 0 at launch.
This is code I know works using a UIViewController:
UIImage *background = [UIImage imageNamed:#"bg_004.png"];
self.backgroundImageView = [[UIImageView alloc] initWithImage:background];
self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:self.backgroundImageView];
self.blurredImageView = [[UIImageView alloc] init];
self.blurredImageView.contentMode = UIViewContentModeScaleAspectFill;
self.blurredImageView.alpha = 0;
[self.blurredImageView setImageToBlur:background blurRadius:10 completionBlock:nil];
[self.view addSubview:self.blurredImageView];
This is the code I am trying on the UITableViewController that does not work:
UIImage *background = [UIImage imageNamed:#"bg_004.png"];
self.backgroundImageView = [[UIImageView alloc] initWithImage:background];
self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.tableView setBackgroundView:self.backgroundImageView];
// Also tried this, to no success
[self.tableView.backgroundView addSubview:self.blurredBackgroundView];
self.blurredBackgroundView = [[UIImageView alloc] init];
self.blurredBackgroundView.contentMode = UIViewContentModeScaleAspectFill;
self.blurredBackgroundView.alpha = 0;
[self.blurredBackgroundView setImageToBlur:background blurRadius:10 completionBlock:nil];
[self.tableView setBackgroundView:self.blurredBackgroundView];
// Also tried this, to no success
[self.tableView.backgroundView addSubview:self.blurredBackgroundView];
If anyone has some suggestions how how to make this work, i'd love some advice. I really wouldn't like to change my code from a TableViewController to a UIViewController
Set the table view's backgroundView property to point to an instance of UIView, and then add your image views as subviews of the new view. You can't directly add subviews to instances of UIImageView
I am displaying UIImageViews programmatically. It works fine with the first UIView but when I try to display it on the smaller view, it does not resize.
Can you help me. Thanks in advance
By the way, I have a custom class of my UIView called courtView. I use this class for the two UIView
UIImageView *newImage;
NSSet *ballPosition = [self.startPosition valueForKey:#"ballPosition"];
for (BallPosition *courtPosition in ballPosition) {
PlayerPosition *player = [courtPosition valueForKey:#"playerPosition"];
if ([player.team isEqual: #(1)]) {
newImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Btn_blue.png"]];
}
else if ([player.team isEqual: #(2)]){
newImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Btn_red.png"]];
}
else if ([player.team isEqual: #(0)]){
newImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Ball.png"]];
}
newImage.frame = CGRectFromString([courtPosition valueForKey:#"courtPosition"]);
[self.courtView addSubview:newImage];
}
try this code
UIImage *myImage = [UIImage imageNamed :#"myImage.extension"];
//if ur images are static, if your images are from an array then loop it out write the below inside the loop, make sure myImageView is a class,static component.
CGFloat height = myImage.size.height;
CGFloat width = myImage.size.width;
myImageView.frame = CGRectMake (myImageView.frame.origin.x,myImageView.frame.origin.y,height,width);
myImageView.image = myImage;
Hope this helps
I'm using iCarousel library in my small app. I'm getting the image urls via web service and placing those images to the iCarousel library.
First I created a UIView and added iCarousel as respective class to it. Latter set the datasourse and delete gate to same class.
Now everything looks cool and I could see the images but I couldn't swipe the images.
Following is my code.
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
//return the total number of items in the carousel
return [galleryItems count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
//create new view if no view is available for recycling
if (view == nil)
{
//NSString *ImageURL = #"YourURLHere";
//NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
//imageView.image = [UIImage imageWithData:imageData];
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
//[((UIImageView *)view) setImageWithURL:[NSURL URLWithString:#"http://www.pizzatower.com/img/icons/Pizza-icon.png"]];
NSURL *imageURL = [[galleryItems objectAtIndex:index] galleryURL];
[((UIImageView *)view) setImageWithURL:imageURL];
view.contentMode = UIViewContentModeScaleAspectFit;
label = [[UILabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.font = [label.font fontWithSize:20];
label.tag = 1;
// label.contentMode = UIViewContentModeBottom;
// label.frame = CGRectMake(
// self.view.frame.size.width - label.frame.size.width,
// self.view.frame.size.height - label.frame.size.height,
// label.frame.size.width,
// label.frame.size.height );
//label.bounds = view.bounds;
[view addSubview:label];
}
else
{
//get a reference to the label in the recycled view
label = (UILabel *)[view viewWithTag:1];
}
//set item label
//remember to always set any properties of your carousel item
//views outside of the `if (view == nil) {...}` check otherwise
//you'll get weird issues with carousel item content appearing
//in the wrong place in the carousel
//label.text = [[galleryItems objectAtIndex:index] galleryDescription];
return view;
}
I've used same code base and it worked in some other project. No idea what am I missing here. Can someone please enlighten me.
You UIView containing the carousel may have userInteractionEnabled set to NO.
Another possibility is that the UIView containing the carousel may be smaller than the carousel and so be blocking interaction. Try setting its background color to see its true size.
I'd suggest delete your nib or the ViewController in your storyboard and re-create it. I had the same issue once and after re-creating it it worked. Make sure you center your UIView when placing it (both horizontally and vertically)