I am trying to change the height of my textview through code when the 4 inch screen is detected. Unfortunately I cant get my current code to work. Can anyone see what is wrong? Both ways its written it doesn't work. In the code I show both ways I've tried. I have this written in viewDidLoad method too.
If this cannot be worked out then can anyone help me out to set height attribute value in attribute inspector for both the screens (with height 568 and 480)
my code,
if ((int)[[UIScreen mainScreen] bounds].size.height==568)
{
[myTextView setFrame:CGRectMake(20.0f, 78.0f, 280.0f, 415.0f)];
}
uncheck 'use autolayout' from interface builder and use 'autosizing' from interface builder to resize your textview height
Related
I am using an iOS UIView for Custom control in Xamarin.IOS. I have used this control in Xamarin.Forms Xaml.
If I set my Grid Horizontal and VerticalOptions="CenterAndExpand", My Draw() in UIView never gets called. It works fine if i set the value to 'FillAndExpand'.
My requirement is to place my custom control in center of my screen.
Is there any way to handle this? or is there other way I could display my UIView in Center of my screen.
<ScrollView>
<Grid HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
<localControls:CustomUIView />
</Grid></ScrollView>
I need this Draw(CGRect rect) method to get the Width and Height of the available size in Screen. Hence my Draw is mandatory.
You can use AbsoluteLayout to let the view to the center of screen.
Views within an AbsoluteLayout are positioned using four values:
X – the x (horizontal) position of the view's anchor
Y – the y (vertical) position of the view's anchor
Width – the width of the view
Height – the height of the view
Each of those values can be set as a proportional value or an absolute value.
Values are specified as a combination of bounds and a flag. LayoutBounds is a Rectangle consisting of four values: x, y, width, height.
Code in Xaml like this:
<ContentPage.Content>
<AbsoluteLayout>
<local:MyCustomView AbsoluteLayout.LayoutBounds="0.5,0.5,300,200" AbsoluteLayout.LayoutFlags="PositionProportional" BackgroundColor="Red"/>
</AbsoluteLayout>
</ContentPage.Content>
AbsoluteLayout.LayoutBounds="0.5,0.5,300,200" AbsoluteLayout.LayoutFlags="PositionProportional" means the anchor is the center of the screen. And the view's Width and Height is 300 and 200.
It works like this:
BTW, I tried your code, but it works fine on my side with Visual Studio 15.3.5 and Xamarin.iOS 11.0.0.0, updating yours may solve the CenterAndExpand issue.
I want to change the properties of my layout, like the margins or the position (above, rigth of, left of..) when there's not internet access and AdMob ads cannot be shown. I don't know how to change these layout properties in my activities and set the layout to full screen. Anyone can help me? Thanks
If the layout is occurring in a LinearLayout, Set the addView layout's visibility to View.GONE
If you are using a RelativeLayout and using margins to prevent the addLayout overlapping your content, then try something like this:
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.setMargins(0,0,0,0);
myLayout.setLayoutParams(lp);
I am implementing a new class that extends CheckBox
In the constructor I am giving it a specific dimensions like this:
setHeight(size);
setWidth(size);
measure(size, size);
But whenever I call getHeight() or getWidth() it always gives me 0.
Am I doing something wrong?
It looks like you are trying to get your views width and height before it is initialized. This is the reason why you need to be more specific when you say whenever especially if you put your code in onCreate. If your view is visible at all try adding simple onClick and get and Log your width and height then and see what happens.
Hope this helps and enjoy your work.
I have two ViewControllers - the main one is Portrait only - the second, which displays a WebView loaded with a YouTube video can rotate to any orientation. When it is dismissed in Landscape, returning to the main ViewController, the status bar is left in Landscape mode. I know when the YouTube view is dismissed and have placed the following line on code in the called method:
UIApplication.SharedApplication.SetStatusBarOrientation(UIInterfaceOrientation.Portrait,true);
But it has no effect on the status bar. Is there some other place to set the orientation? Other ideas?
Thanks,
Rick
Fixed the problem by adding the following to the AppDelegate
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations (UIApplication application, UIWindow forWindow)
{
return UIInterfaceOrientationMask.AllButUpsideDown;
}
Then this code actually did what it is supposed to:
UIApplication.SharedApplication.SetStatusBarOrientation(UIInterfaceOrientation.Portrait,true);
I have a ViewController with a UIWebView, in a Objective-c project for iPad.
When I add html (with loadHtmlString), I try to keep the scroll position it had before the loadHtml, but I cannot help and it returns to the top.
Here are the lines I use:
scrollPosition = [[webView stringByEvaluatingJavaScriptFromString: #"scrollY"] intValue];
[webView loadHTMLString:html baseURL:nil];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.scrollTo(0, %d);",scrollPosition]];
I tested the value 'scrollY' at different locations in my code
and it stays at the value scrollPosition that I want, but when it ends up showing on the screen the WebView is always at the top (with the scrollY value then to 0).
Is there someone who could help me figure out why this happens?
I checked for hours the answers online, also on StackOverflow.
I tried different solutions (like adding in my webview the JavaScript "onclick="scroll(); return false;", but to no avail.
I tried to self-delegate the webView and update the scrollTo in webViewDidFinishLoad, but it seems that webViewDidFinishLoad is not called (the breakpoint is not reached) although I did add in .h in the interface and in the .m in ViewDidLoad the line: webView.delegate=self;
Thank you in advance for any help.
I realized that after recompiling, webViewDidFinishLoad was called after the html was updated, and that I could then scroll to the correct position.
For the self delegation I used in viewDidLoad, it looks so:
webview.delegate = self;
Before updating the html in the webView I calculate the scrolling position with the code:
scrollPosition = [[wbView stringByEvaluatingJavaScriptFromString: #"scrollY"] intValue];
Then, for moving back to this position once the webView has an updated html, I then use:
-(void) webViewDidFinishLoad:(UIWebView *)wbView {
[wbView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.scrollTo(0, %d);",scrollPosition]];
}
I found part of the solution through the post below, with the answer of Pawel:
How can I scroll programmatically to the bottom in a uiwebview