I'm having trouble displaying content properly in a splitview application. In the detail view I have a webview and I'm loading locally saved html files. However the files don't display properly - they are slightly zoomed in and missing detail on the left and right. Double taping them zooms them out and they display correctly. I have scaletofitpages=YES set.
Any advice?
Well, if i'm understanding you correctly, you can use auto layout.. it will fit your content from left and right.
to set the font size you must edit your html content add "css style" to them...
// Get result into string format
NSString *htmlData = [objSQLiteProtocol getDatabaseResults:fileNameToRead];
// reduce the size of font to set in iPad
htmlData = [htmlData stringByReplacingOccurrencesOfString:#"25pt" withString:#"12pt"];
[moreWebView loadHTMLString:htmlData baseURL:nil];
moreWebView.scalesPageToFit = YES;
Related
I need to change the image programmatically that PathMenu uses to design.
I have a PaintCode generated StyleKit which draws .SVG files, not an image in a Asset.xcassets.
PathMenu uses something like this to take the images:
let menuItemImage = UIImage(named: "bg-menuitem")!
but I need to make something like
let menuItemImage = myImageFromMyStyleKit
How can I make this work?
In PaintCode document, select canvas and in Inspector, select StyleKit Image Method from dropdown menu in Code Export section.
This canvas will then generate imageOfCanvas... method, instead of drawCanvas... method. This way, you can then simply obtain image of this canvas and use it in the menu item.
PathMenuItem(image: StyleKit.imageOfCanvas)
I have a couple of custom cells and web views inside each of these cells. Now,my requirement is to find the height of the HTML string to be loaded on the webview, then based on this change the Custom cell height and the webview height.
I am aware that the document's height can be found in the -webViewDidFinishLoading delegate, but in my app i have a lot of cells and webviews inside each of these cells, so i feel that the app would slow up while scrolling and making unnecessary callbacks
At present i am doing this which gives me the string height.
-(float)getDynemicHeight:(NSString *)pstrText
{
CGSize constraint = CGSizeMake(683,600);
CGSize size = [pstrText sizeWithFont:[UIFont systemFontOfSize:18] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height, 44.0f);
if (height>400) {
return 400;
}
return height;
}
This however causes a problem as even <div> elements are considered as string and hence a larger value of height is returned
In iOS 6, if you just want to show styled text (not text with images mixed in or something like that), you might like to use NSAttributedString instead of a web view. It allows you to create text with different styles in different stretches of text, paragraph margins, etc. etc. Its metrics are well defined and it comes with measurement methods. Simple UIView subclasses such as UILabel can now display an attributed string. Or you can just draw it yourself, directly into the interface.
http://www.apeth.com/iOSBook/ch23.html#_attributed_strings
If you can't do that, then what you're trying to do is basically impossible. You don't know how the Web view will draw a piece of complex HTML until it has drawn the complex piece of HTML. You will simply have to change your app's architecture. For example you could draw all the Web views way ahead of time so you have the needed info during table-dataSource time.
I want to build a website that looks exactly the same across all screen width's, which means the whole website will scale according to the screen's, or more accurately, the viewport's width.
This is relatively easy to do for SVG images and I have all images correctly scaling according to the viewport's width. The viewport's width is the point of reference, from which all images scale. However, the point of reference for the text is different between any desktop browser and the iPhone's Safari (and I assume any mobile browser).
According to my research there seem to be two possible reasons for different sized text: a difference in the default CSS's or a difference in the rendering engines. Since I can't find any reference to pixel sized text on Chrome's default CSS or Firefox's default CSS, I assume this setting comes from the rendering engine.
My IP is dynamic so I can't provide a live example, but here are the screens comparing the same site in iPhone's Safari and Chrome on the desktop. Notice the huge difference in the size of the text.
Is there any way I can make the text have the same relative size in both these browsers?
I found the answer in JavaScript:
onresize=onload=function(){
document.body.style.fontSize=window.innerWidth/20+"px"
}
which sets the text size according to the viewport's width on the body element. Since all the text set in em's is sized in relation to their parents, all the text is sized correctly from the body element.
Furthermore, if you want to avoid the cascading hell by using rems and respect the original layout design from a let's say 1024px width you can stick with this:
onresize = onload = function(){
document.querySelector("html").style.fontSize = ( innerWidth * 100 ) / 1024 + "%";
}
You should try CSS Unit vw, like this:
body { font-size: 1.5vw; }
However, i am not sure it is supported by mobile browsers...
EDIT
Check for browser compatibility here.
I am using Linear Layout to display image view and text view.
I am getting the response from server by using XML parsing.
When i am getting the new response from server the second image view and related text will be displayed in the bottom of the new Layout and so on.
but i want to display the image with related text in the above of the previous Layout.
if any one see this question, please help me.
Thanks in advance.
You can add it programmatically with:
LinearLayout layout = findViewById(R.id.layout);
layout .addView(newView, index);
You just have to add always with index = 0
I have parsed html content to display in a webview.
There are phone numbers which are detected by webview by default, but those links are displayed in blue color, I want to change it to white color, how is it possible?
If anyone know please tell me..
Thanks in advance.
According to this question all you need to do is to set the a (hyperlink) CSS properties. See the answer of David Thomas. Specifically, he proposes this solution for just phone URLs:
a[href^=tel] { /* css */ }
You can change style color of your html content on server side or in client side.
For doing it from client side you must get first the elementId or class of your html content (you can do it from chrome with right mouse click on the link and selecting inspect element)
Then on your uiwebview (once it finished being loaded) you execute javascript for changing element color:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *javascripString = [NSString stringWithFormat:#"document.getElementById(\"linkId\").style.color=\"white\";", m_studyId];
[uiwebview stringByEvaluatingJavaScriptFromString:javascripString];
}
The iPhone uses the current color setting in the a:link property. It uses that value even if the phone number is plain text and not enclosed with the hyperlink tag. If no CSS definition is set, iPhone uses the default. For those who may not know, you can set the values like this.
<head>
<style>
a:link {
color:#FFCC14;
text-decoration:underline;
}
</style>
</head>
If you do not have a CSS style setting for hyperlink then add it or Change the color to the color that works best for your webpage.
Try DarkDust solution. From client side it would be something like that:
- (void)webViewDidFinishLoad:(UIWebView *)webView{
NSString *javascripString = [NSString stringWithFormat:#"document.createElement('meta');meta.name='format-detection';meta.content='telephone=no';document.getElementsByTagName('head')[0].appendChild(meta);"];
[webView stringByEvaluatingJavaScriptFromString:javascripString];
}