set left X-position of UITableViewCellAccessory - uitableview

in moreNavigationController I try to change the arrow position in cells.
It works on an iPhone but not on an iPad.
The origin X-position on the iPhone is AFTER the seperator line ends,
on the iPad it's much more BEFORE the separator ends.
It works fine to change the position more to the left side with this Code on an iPhone:
UIImageView *arrowImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed : AppInfo::getArrowIconResource()]];
[[-moreTableView cellForRowAtIndexPath:row] setAccessoryView : arrowImage];
CGRect frame = arrowImage.frame;
frame.size.width = 50;
arrowImage.frame = frame;
[arrowImage setContentMode:UIViewContentModeLeft];
The arrow position in the cell changed to the left! And it ends with the separator line.
On the iPad nothing seems to change the x-Position to the right (so the separator line is too long).
It does not matter which value i set (50,-50), nothing change the arrow more to the right position.
[arrowImage setContentMode:UIViewContentModeRight]; has no effect
Has any an idea?

Related

how to make a rectangle at run time to fit a dragged label of words in it objective c

I am making a words match app in iOS in which i have two parts of words strings and I want to make a complete word from two labels of random words so for all is fine.
Now I want to make a rectangle at run time as a target of draggable label, when I click on label to drag it the rectangle should become hi-lighted with the same size as the size of label of words.
How can i achieve this in objective-C?
For more clearness you can see in image where I want to make this green rectangle at run time to drop the right side labels in it
The left side labels are not moveable and should always in the rectangle as you see in given image.The code so far i try to make the rectangle as a UIView in viewDidLoad as
for(int i = 0; i <5;i++){
customView = [[UIView alloc]initWithFrame:CGRectMake(10,y,50, 30)];
customView.backgroundColor = [UIColor greenColor];
[gameLayer addSubview:customView];
y = y+40;
}
But this is not what i actually want. Any help appreciated...
Finally i got the rectangle size same as the size of tapped label as here, i make an array in .h file which contain the reference of my target rectangle NSMutableArray *rectangleLabels
after that i make the size of rectangle same as the size of my draggable labels using a loop in tapped gestures method and it works fine...
-(void)gotTapped:(Id)sender {
for (UIView *v in rectangleLabels) {
v.hidden = !v.hidden;
UILabel *tapLbl = (UILabel *)[sender view];
CGRect rect = tapLbl.frame;
for(int i=0;i<rectangleLabels.count;i++) {
UILabel *lblChange = (UILabel *)[rectangleLabels objectAtIndex:i];
lblChange.frame = CGRectMake(lblChange.frame.origin.x, lblChange.frame.origin.y, rect.size.width, rect.size.height);
}
}
}

Layout in UIScrollView

I am new to UIScrollView, and they are driving me crazy.
I am trying to create a screen that has a title and some descriptive text at the top, and then a scroll view (with paging enabled) in the bottom two thirds of the screen. This scroll view will contain 1-3 images. Ideally, I'd like the first image to appear centered in the initial scroll view window, and then enable the user to view the other images by scrolling/paging horizontally, again ideally with each image centered in its 'page'.
The code below loads the images for 'item' from the Internet, creates a UIImageView for each, and inserts them into the scroll view. According to the frame calculations, I would expect the first image to be up against the left side of the scrollview, and then the other images to the right, with no space between them. But instead, the first image is shifted to the right, about half-way across the screen, and there are equally large spaces between each image.
I have turned off paging to simplify matters, and I have tried experimenting with tweaking the image frame values, trying to understand what's happening, but nothing works as I expect it to.
I am guessing that autolayout is messing with me. Can someone confirm that, and maybe give me some hints on how to get this scrollview under control?
Thanks in advance.
self.imageScrollView.contentSize = CGSizeMake(self.imageScrollView.frame.size.width * (imageFieldNames.count),
self.imageScrollView.frame.size.height);
self.imageScrollView.pagingEnabled = NO;
CGFloat xPos = 0.0;
for (NSString *field in imageFieldNames) {
NSString *name = [self.item valueForKey:field];
if (name.length > 0) {
UIImageView *iv = [[UIImageView alloc] init];
iv.contentMode = UIViewContentModeScaleAspectFit;
[self loadImage:iv withFile:name];
iv.frame = CGRectMake(xPos, 0.0,
self.imageScrollView.frame.size.width,
self.imageScrollView.frame.size.height);
[self.imageScrollView addSubview:iv];
xPos += self.imageScrollView.frame.size.width;
}
}

UIButton background image used for animation not aligned across devices

I have a UIButton backgroundImage that I use to display a weather condition image when the loading is complete. I also create a UIImageView that replaces the UIButton to animate a series of images as a progress indicator.
My question: How can fix this animated UIImageView x-axis misalignment across multiple screen sizes?
Here's what the sequence looks like on 4.7" iPhone, the red box indicates the image I'm talking about:
First, the UIImageView animating as a progress indicator (imagine it spinning, alignment is correct)
Second, the download complete, the progress indicator replaced by a UIButton with a backgroundImage:
Third, the UIImageView animating on 4" iPhone (note misalignment on x-axis):
Fourth, the download complete, UIButton replaces it, aligned correctly:
Here's how the UIImageView *progressIndicator is configured.
Note that conditionButton is the UIButton with backgroundImage of the weather condition:
self.progressIndicator = [[UIImageView alloc] initWithFrame:self.conditionButton.frame];
self.progressIndicator.contentMode = UIViewContentModeCenter;
self.progressIndicator.animationImages = #[...long series of images...];
self.progressIndicator.animationDuration = 0.5f;
[self.conditionButton setBackgroundImage:[UIImage imageNamed:#"empty.png"] forState:UIControlStateNormal];
[self.progressIndicator startAnimating];
[self.view addSubview:self.progressIndicator];
I'm pretty sure the issue is with
self.progressIndicator = [[UIImageView alloc] initWithFrame:self.conditionButton.frame];
But I'm not sure how to resolve this.
The same problem occurs when I switch to 5.5" iPhone. I have no Auto Layout warnings, and the constraints that apply to the conditionButton are:
Align Center X to superview
Width = 94
Height = 94
Bottom and Top space to nearest neighbor = default
Any help would be greatly appreciated!

Dynamically changed UIImage width

I have UIImage like this with place for UITextField at free white space between red lines at left side:
UIImage real borders bigger than visible part because gesture recognizer linked to this image and it needs to be bigger for more comfortable using with gestures.
Text alignment in text field set to right side. So task is to crop image frame from left side depending on entered text length, when keyboard dismissed after entering text. I used this code:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
ruleImage.layer.anchorPoint = CGPointMake(1,1);
[ruleImage setFrame:CGRectMake(0, 0, 120 + ruleTextfield.text.length * 15 , ruleImage.frame.size.height)];
}
But this code compressed image horizontally, not cropped, and from left to right. So questions:
how to set anchor point to top (or bottom)right corner?
what property can I use to crop image?
P.S. also I tried
ruleImage.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
ruleImage.contentMode = UIViewContentModeTopRight;
but this properties not solved my problem.
Try
ruleImage.contentMode = UIViewContentModeScaleAspectFill;

Make an UIImageView and its UIImage scale proportionally without extra padding

I have an UIView that contains a UIImageView. The UIImageViews works like the branding logo of the app. When I rotate the device, the containing UIView resizes itself to correspond to the landscape or portrait proportions of the screen.
What I'm trying to achieve is to have the UIImageView scaled accordingly, keeping proportions also on the left margin.
This is the actual code for the top white "banner":
UIView *topBanner = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, height_topBanner)];
[topBanner setAutoresizingMask:(UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin)];
[topBanner setBackgroundColor:[UIColor whiteColor]];
topBanner.autoresizesSubviews = YES;
// the logo
UIImage *topBanner_logo = [UIImage imageNamed:#"logo.png"];
float logoAspectRatio = topBanner_logo.size.width/topBanner_logo.size.height;
topBanner_logoView = [[UIImageView alloc] initWithFrame:CGRectMake(topBanner.frame.size.width/100*3, topBanner.frame.size.height/100*7, (topBanner.frame.size.height/100*86)*logoAspectRatio, topBanner.frame.size.height/100*86)];
[topBanner_logoView setImage:topBanner_logo];
topBanner_logoView.backgroundColor = [UIColor blueColor];
topBanner_logoView.contentMode = UIViewContentModeScaleAspectFit;
[topBanner_logoView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleRightMargin)];
[topBanner addSubview:topBanner_logoView];
[self.view addSubview:topBanner];
This is my starting point: portrait iPad on startup:
This is what happens when I rotate it in landscape:
As you can see, the proportions of the UIImage are ok, but I'm getting extra borders (I set the background color of the UIImageView to highlight it) because the UIImageView stretches itself to follow the change of the size of its container, and the UIImage is fit into the UIImageView and put on its center.
The same - reversed - happens when I start the app directly in landscape mode:
Then I rotate it:
... and I get the logo with extra borders on top and bottom.
I do see that I can write a function to recalculate every size on each rotation change, but I'm asking to myself if is there a way to set the UIImageView and the UIImage to make it works without hacking the autorotate/resize procedures of iOS. It sounds so simple!
You can solve this by not using UIViewContentModeScaleAspectFit, and instead calculating the aspect ratio of the image and using that to explicitly the width or height based on the other (width or height).
e.g. I rotate to landscape, and so I want the height to be 80% of the view.
CGFloat w = logo.image.size.width;
CGFloat h = logo.image.size.height;
CGFloat a = w / h;
CGFloat h_use = self.view.height *0.8;
CGFloat w_use = h_use*a;
Furthermore, set the content mode to UIViewContentModeScaleAspectFill instead now that you've explicitly set the aspect ratio.
You have set the auto resizing mask to flexible height and width:
[topBanner_logoView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleRightMargin)];
If you do not do that, the default is that the view will not chance size, and therefore, the image will not either.
I think it is because of topBanner_logoView.contentMode = UIViewContentModeScaleAspectFit;
Try topBanner_logoView.contentMode = UIViewContentModeCenter or topBanner_logoView.contentMode = UIViewContentModeLeft to prevent the UIImageView's image from resizing (and getting padding).
If the UIImageView is resizing, remove the autoresizing mask.

Resources