ScrollView doesn't work on iPad but works on iPhone - ios

I have a scrollview and it is full off buttons. this scrollview work iphone but not work on ipad
#define scrollViewSizeForiPad 1000
#define scrollViewSizeForiPhone 600
#define locationButtonSizeForiPhone 50
#define locationButtonSizeForiPad 30
i added buttons like this
lc_button.frame = CGRectMake(0, 0, buttonSize, buttonSize);
[_uiScrollForLocations addSubview:lc_button];
and some labels
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad){
buttonSize = buttonWidthHeightForiPad;
lc_label.font = [UIFont systemFontOfSize:14];
lc_label.frame = CGRectMake(3, 100, buttonSize, 20);
} else {
buttonSize = buttonWidthHeightForiPhone;
lc_label.font = [UIFont systemFontOfSize:9];
lc_label.frame = CGRectMake(8, 50, buttonSize, 10);
}
[_uiScrollForLocations addSubview:lc_label];
-(void) showLocations:(NSMutableArray *)lc_array {
[self hideAllLocations];
[self addButtonToView:lc_array whichView:_uiScrollForLocations type:#"Location"];
CGSize pagesScrollViewSize = _uiScrollForLocations.frame.size;
int viewHeight;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad){
viewHeight = buttonWidthHeightForiPad;
} else {
viewHeight = buttonWidthHeightForiPhone;
}
_uiScrollForLocations.contentSize = CGSizeMake(pagesScrollViewSize.width, viewHeight);}

It happen because contentSize <= _uiScrollForLocations.frame
Need set
_uiScrollForLocations.alwaysBounceVertical = YES
or
_uiScrollForLocations.alwaysBounceHorizontal = YES

Related

Resize button / image by user's choice

,I would like to give the user the option to select the button size as per the user's choice ... Can I do this please?
mytweak.xm
UIButton *respringButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
respringButton.frame = CGRectMake(self.view.frame.size.width - 250, self.view.frame.size.height / 2 - 80, 60, 60);
[respringButton setImage:[UIImage imageWithContentsOfFile: respring] forState:UIControlStateNormal];
[respringButton setTitle:#"respring" forState:UIControlStateNormal];
[respringButton addTarget:self action:#selector(reboot) forControlEvents:UIControlEventTouchUpInside];
if(style != 1) {
respringButton.tintColor = tintColor;
} else {
if(defaultTheme1 == 0) {
respringButton.frame = CGRectMake(self.view.frame.size.width - 250, self.view.frame.size.height , 60, 60);
} else if (defaultTheme1 == 1) {
respringButton.frame = CGRectMake(self.view.frame.size.width - 250, self.view.frame.size.height , 80, 80);
} else if (defaultTheme1 == 2) {
respringButton.frame = CGRectMake(self.view.frame.size.width - 250, self.view.frame.size.height , 100, 100);
}
}
[respringButton centerVertically];
[myView addSubview:respringButton];
mytweak.h
- (void)centerVertically {
// Spacing between the text and the image
CGFloat spacing = 5.0;
// Lower the text and push it left so it appears centered below the image
CGSize imageSize = self.imageView.frame.size;
self.titleEdgeInsets = UIEdgeInsetsMake(0.0, - imageSize.width, - (imageSize.height + spacing),- 120.0);
// Raise the image and push it right so it appears centered above the text
CGSize titleSize = self.titleLabel.frame.size;
self.imageEdgeInsets = UIEdgeInsetsMake(- (titleSize.height + spacing), 0.0, 0.0, - titleSize.width);
}
#end

iOS 11.2 custom navigation bar infinite loop

Since the release of IOS 11.2 my app is encountering an infinite loop when pushing a view controller whose navigation controller has a custom navigation bar height. Did someone find the solution for this problem? Thanks.
-(void)layoutSubviews{
[super layoutSubviews];
float height = 42.5;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
height = 48;
}
imageView.frame = CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, height);
if(UI_USER_INTERFACE_IDIOM() ==UIUserInterfaceIdiomPad){
if(#available(iOS 11.0,*)){
self.frame =CGRectMake(0, 20,[[UIScreen mainScreen]bounds].size.width, 55); // this line provoke the infinite loop
for(UIView *aView in self.subviews){
if([NSStringFromClass([aView class]) isEqualToString: #"_UINavigationBarContentView"]){
aView.frame = CGRectMake(0, 10, aView.frame.size.width, aView.frame.size.height);
}
if([NSStringFromClass([aView class]) isEqualToString: #"_UIBarBackground"]){
aView.frame = CGRectMake(0, 0, aView.frame.size.width, self.frame.size.height );
}
}
}
}
}
I also had the same problem.
I solved by removing this
frame.size.height = customHeight
from layoutSubviews and then adding this
override var frame: CGRect {
get {
return CGRect(x: 0, y: 0, width: super.frame.width, height: customHeight)
}
set (value) {
super.frame = value
}
}
to my UINavigationBar subclass.
I left all other code in layoutSubviews as it was before. (nb)

App behaviour changes after disconnected from xcode

I am developing a new release of my app and have come across a very frustrating issue. i have some code that repositions a view on the screen after rotation(see below code) When i run it in the simulator there are no issues, when i test on a physical device there is also no issue, until i disconnect from xCode. After disconnecting from Xcode the view no longer re locates correctly. If i reconnect to Xcode and run again it still won't work as it used to/expected. I added the logging you see in the code and now know that on first execution the heigh and with are logging correctly but after disconnect they are reversed. I have also installed an adhoc distribution to a two different devices and again on first execution everything works fine(no Xcode connection this time). But if i completely close the app (double tap home and wipe up) on the next execution we get exactly the same outcome as before with the view repositioning off the screen(presumably the NSlog values will again be reversed). I have searched high and low and can't find any solutions at all.
- (void)deviceOrientationDidChangeNotification:(NSNotification*)note
{
NSLog(#"rotate");
int height = [UIScreen mainScreen].bounds.size.height;
int width = [UIScreen mainScreen].bounds.size.width;
NSLog(#"%#,%d",#"height: ",height);
NSLog(#"%#,%d",#"width: ",width);
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (UIDeviceOrientationIsPortrait(orientation)==YES){
if ([self.vcID.text isEqualToString:#"i4"]) {
self.addheightCont.constant = 50;
}else{
self.addheightCont.constant = 100.0;
}
}else if (UIDeviceOrientationIsLandscape(orientation)==YES){
if ([self.vcID.text isEqualToString:#"i5"]) {
self.addheightCont.constant = 32.0;
}else if ([self.vcID.text isEqualToString:#"i4"]) {
self.addheightCont.constant = 32.0;
}else{
self.addheightCont.constant = 50.0;
}
}
if (height==568) {
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 320, 568);
self.imageScroller.frame = CGRectMake(0, 0, 320, 568);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(160, 284)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 445)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 445)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(160, 284)];
}
}else if (height==480){
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 320, 480);
self.imageScroller.frame = CGRectMake(0, 0, 320, 480);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(160, 240)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 445)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 445)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(160, 284)];
}
}else if ((height==320) && (width==568)){
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 568, 320);
self.imageScroller.frame = CGRectMake(0, 0, 568, 320);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(277, 160)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 304)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 304)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(284, 160)];
}
}else if ((height==320) && (width==480)){
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 480, 320);
self.imageScroller.frame = CGRectMake(0, 0, 480, 320);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(240, 160)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 304)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 304)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(284, 160)];
}
}else if ((height==375) && (width==667)){
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 667, 375);
self.imageScroller.frame = CGRectMake(0, 0, 667, 375);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(333.5, 187.5)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 304)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 304)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(333.5, 115)];
}
}else if (height==667) {
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 375, 667);
self.imageScroller.frame = CGRectMake(0, 0, 375, 667);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(187.5, 333.5)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 445)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 445)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(187.5,115)];
}
}else if (height==736) {
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 414, 736);
self.imageScroller.frame = CGRectMake(0, 0, 414, 736);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(207, 333.5)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 514)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 514)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(207,115)];
}
}else if (height==414){
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 736, 414);
self.imageScroller.frame = CGRectMake(0, 0, 736, 414);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(368, 187.5)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 380)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 380)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(368, 115)];
}
}
}
After Fahim's suggestion i did some research on auto layout and as a result have managed to implement a fix using auto layout. I have set a constraint for the distance of the comment view from the top and sides of the top of the parent view and simply change the constant values using the code below to animate the view on and off the screen. As a result i no longer need any of the code in my question in the view rotation. Although i didn't find an answer to why the behaviour changes when the phone is disconnected from Xcode its no longer an issue with auto layout doing all the work.
To animate the view on screen i use:
[UIView animateWithDuration:0.5 animations:^{
self.CommentViewOffset.constant = 40;
[self.view layoutIfNeeded];
}];
And off the screen i use:
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
[UIView animateWithDuration:0.5 animations:^{
if (UIDeviceOrientationIsPortrait(orientation)==YES){
self.CommentViewOffset.constant = 750.0;
self.editComentViewOffset.constant = 750;
[self.view layoutIfNeeded];
}else if (UIDeviceOrientationIsLandscape(orientation)==YES){
self.CommentViewOffset.constant = 440;
self.editComentViewOffset.constant = 440;
[self.view layoutIfNeeded];
}
Now i have no need to do anything in the deviceOrientationDidChangeNotification method as everything is handled with auto layout. I must say i have avoided auto layout completely until now and really wish i had taken the time to do the research earlier.

UIViews in scrollviews

I have a UIScrollview with UIView, and in every UIView has a labels and image. I'm looping this view and it's working fine, but I have a button Grid and when i press this they changed into grid view. The problem is the last item is not working fine as the others. One of the labels are hidden in the last item. And when I pressed the list view button, the last item has a problem again, the labels are complete but the 'View' didn't changed.
-update.
the content size is okay, and it's leaving a space for the last item but the last item is somewhere. I can't post images yet because of the reputation.
`-(void)actionList {
int prods = 0;
isGrid = NO;
for(UIView*iView in sv_results.subviews){
for(UILabel *iView2 in iView.subviews){
if([iView2 isMemberOfClass:[UILabel class]]){
if(iView2.tag == 0)
{
iView2.frame = CGRectMake(80, 0, 150, 50);
iView2.font = [UIFont boldSystemFontOfSize:12.0f];
NSLog(#"%#",iView2.text);
}
else if(iView2.tag == 1)
{
pricewidth = [iView2.text sizeWithAttributes:#{NSFontAttributeName:[UIFont systemFontOfSize:13.0f]}];
iView2.frame = CGRectMake(80, 20, pricewidth.width+1, 50);
iView2.font = [UIFont systemFontOfSize:13.0f];
for(UIView *discountline in iView2.subviews)
{
discountline.frame = CGRectMake(0, iView2.frame.size.height/2, iView2.frame.size.width, 1);
}
}
else if(iView2.tag == 2)
{
iView2.frame = CGRectMake(screenRect.size.width-60, 30, 50, 15);
iView2.font = [UIFont systemFontOfSize:10.0f];
}
else if(iView2.tag == 3)
{
iView2.frame = CGRectMake(140, 20, 150, 50);
iView2.font = [UIFont systemFontOfSize:13.0f];
}
}
if([iView2 isMemberOfClass:[AsyncImageView class]]){
iView2.frame = CGRectMake(15,12,50,50);
iView2.layer.cornerRadius = 5;
}
}
NSLog(#"all avail data > %i",allAvailableData);
for(int i = 0;i<allAvailableData;i++)
{
if(iView.tag == i)
{
NSLog(#"UIView tag > %i",iView.tag);
iView.frame = CGRectMake(0,((i-1)*75),320,75);
}
}
prods++;
iView.layer.borderWidth = .3f;
}
NSLog(#"%i",prods);
sv_results.contentSize = CGSizeMake(320,(allAvailableData)*75);
}`

iOS UILabel cannot resize the text

I would like to implement the ULLabelExtended to autosize the text size of the UILabel to the device width. but when it comes to the execution; it shows the picture as the result instead of showing the full clause:
The full clause : Ze aangeplant cocos rond hun nieuwe home.
Are there any other alternatives to get the relationship or functions that text size of label is proportional to the device width ?
The below is my code
Application:
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
[self.labelLong setWidthOfLabelWithMaxWidth:screenWidth];
[self.labelShort setWidthOfLabelWithMaxWidth:screenWidth];
Source:
#import "UILabelExtended.h"
#implementation UILabelExtended
#synthesize selector,customDelegate, objectInfo;
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if(self.selector)
if([self.customDelegate respondsToSelector:self.selector]) {
[self.customDelegate performSelector:self.selector withObject:self];
return;
}
}
- (void)dealloc {
self.customDelegate = nil;
self.selector = NULL;
self.objectInfo = nil;
}
#end
#implementation UILabel(UILabelCategory)
- (void)setHeightOfLabel {
UILabel* label = self;
//get the height of label content
CGFloat height = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(label.bounds.size.width, 99999) lineBreakMode:NSLineBreakByWordWrapping].height;
//set the frame according to calculated height
CGRect frame = label.frame;
if([label.text length] > 0) {
frame.size.height = height;
}
else {
frame.size.height = 0;
}
label.frame = frame;
}
- (void)setWidthOfLabel {
UILabel* label = self;
//get the height of label content
CGFloat width = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(99999, label.bounds.size.height) lineBreakMode:NSLineBreakByWordWrapping].width;
//set the frame according to calculated height
CGRect frame = label.frame;
if([label.text length] > 0) {
frame.size.width = width+5;
}
else {
frame.size.width = 0;
}
label.frame = frame;
}
- (void)setHeightOfLabelWithMaxHeight:(float)maxHeight {
UILabel* label = self;
//get the height of label content
CGFloat height = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(label.bounds.size.width, maxHeight) lineBreakMode:NSLineBreakByWordWrapping].height;
//set the frame according to calculated height
CGRect frame = label.frame;
if([label.text length] > 0) {
if (height > maxHeight) {
frame.size.height = maxHeight;
}
else {
frame.size.height = height;
}
}
else {
frame.size.height = 0;
}
label.frame = frame;
}
- (void)setWidthOfLabelWithMaxWidth:(float)maxWidth {
UILabel* label = self;
//get the height of label content
CGFloat width = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(99999, label.bounds.size.height) lineBreakMode:NSLineBreakByWordWrapping].width;
//set the frame according to calculated height
CGRect frame = label.frame;
if([label.text length] > 0) {
if (width > maxWidth) {
frame.size.width = maxWidth;
}
else {
frame.size.width = width;
}
}
else {
frame.size.width = 0;
}
label.frame = frame;
}
#end

Resources