UITextfield at UISearchbar appears different at simulator and on actual iPhone - iphone

I managed to customize the look and feel of the UITextfield at UISearchBar using the code below:
for (UIView *subview in [searchBar subviews])
{
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarTextField")]){
[(UITextField *)subview setBackground:[UIImage imageNamed:#"background_searchField.png"]];
[(UITextField *)subview setTextColor:[UIColor redColor]];
}
}
It appears exactly what I wanted when I use the simulator. However, when I tested it on an actual iPhone, the background image was not visible.
Please advice. Many thanks.

Do you have the same exact version of iOS on both simulator and device?
Anyway, don't use this black magic, the UISearchFiled is highly customizable through UIAppearance protocol, check "Customizing Appearance" section in reference.
Same goes for UITextField, you can override text color and background using properties, and do more complicated customization in "Drawing and Positioning Overrides"

Related

How to insert UIImageView in UITextView in the same way that iphone default message (SMS) app uses to insert multimedia content in the UITextView

I want to insert UIImageView in UITextView of Toolbar having send and camera button in the same way as iPhone default SMS app do.
You would be better off using a UIScrollView and managing UITextViews and UIImageViews in it. UITextView doesn't support adding image inline with text. In fact, it doesn't really support anything other than multiline text.
Per your comment below, there are three things I can think of to get the image as part of the text entry box:
They're not using a UITextView, but instead some custom view. That sort of thing is difficult to replicate.
They are overlaying a UIImageView over the UITextView as a subview and setting the contentInset of the UITextView so there is no overlap.
They are using a separate UIView to contain both the UITextView and UIImageView as subviews and simply arrange those subviews as needed.
Both 2 & 3 are very similar (just slightly different approaches) and probably your best approach. Personally, I think 3 is probably the best, since it give you the most control over the position of both views, but 2 should also work fine.
I agree with Aaron. Based on what I have seen, I believe the native SMS app is actually a UITableView with highly modified TableCells. The TableCells are then composite views that contain the UITextView and UIImageView as Aaron suggested.
It might be a little more work up front, but I think you will find the customization of defining your own UITableCell with the above elements will be quite useful and fall in line with the overall iOS paradigm. Things work a lot better when you work with the native paradigms than against / around them.
Cheers
I have one suggetion that try to make html file with image and text as per your requirements and load that html file into webview.
Here you can also back some particular text Bold etc.
I think nice look then textfield.
To make webview just look like simple scroll view just put this method in your code
don't forgot to write this
webView.opaque = NO;,
[self hideGradientBackground:webView]; and
- (void) hideGradientBackground:(UIView*)theView
{
for (UIView * subview in theView.subviews)
{
subview.backgroundColor = [UIColor clearColor];
if ([subview isKindOfClass:[UIImageView class]])
subview.hidden = YES;
[self hideGradientBackground:subview];
}
}
I hope this may help you.
You can implement it using UITextViewDelegate and ContentInset.
- (void)viewDidLoad
{
self.textView.delegate = self;
[self.textView addSubview:self.addedView];
[self.textView setContentInset:UIEdgeInsetsMake(0, 0, CGRectGetHeight(self.addedView.frame), 0)];
}
- (void)textViewDidChange:(UITextView *)textView
{
NSLog(#"%#",NSStringFromCGSize(textView.contentSize));
__weak typeof(self) wself = self;
[UIView animateWithDuration:0.5f animations:^{
[wself.addedView setFrame:CGRectMake(0, textView.contentSize.height + 10, CGRectGetWidth(wself.addedView.frame), CGRectGetHeight(wself.addedView.frame))];
}];
}

Is there any other style presenting an UIAlertView?

I saw one app in which the notification/alert view was coming from the top of the iphone screen with gradient black color.
May I have details about alert/notification styles if any?
you may use this link ... maybe it will help you. one other way is to use UIActionsheet.
http://joris.kluivers.nl/blog/2009/04/23/subclass-uialertview-to-create-a-custom-alert/
There's the UIActionSheet—but it is raises from the bottom.
Unfortunately not. And customize the original UIAlertView is a trick, that acts on subviews hierarchies. you can sub class it and change it's background color overriding the drawRect: method and removing the original background with those lines of code
- (void)didAddSubview:(UIView *)subview {
if ([subview isMemberOfClass:[UIImageView class]]) {
[subview removeFromSuperview];
}
}
But it is a trick and it could be lost in future release of iOS

Remove or change color of frame around UIWebView document display?

I'm using a UIWebView to display a variety of file types (so I can't use a specialized PDF viewer) embedded into my main view (so I can't use a modal document interaction controller). My main view has a background design that clashes with the light gray frame that appears around documents in the UIWebView. Does anyone know a way to remove that gray frame, make it transparent or change its color?
I'm familiar with and have used the techniques for changing the background color of the UIWebView to avoid a "color flash" while it loads, and for removing the top and bottom shadow that appear when "overscrolling" the web view, but I haven't seen anyone address this gray frame. (It only appears when displaying documents like .doc or .pdf, not when displaying HTML content.) I've hidden all the images that are subviews of the UIWebView's scroll view, so apparently this is coming from somewhere else.
This question was written while iOS 4 was current, but in iOS 5 and later, simply setting the backgroundColor and opaque properties of the UIWebView will remove that gray frame:
myWebView.opaque = NO;
myWebView.backgroundColor = [UIColor clearColor];
You can change WebView's background color by assigning its backgroundColor property:
myWebView.backgroundColor = [UIColor redColor]; // will make red bakground
If you want transparency use [UIColor clearColor] instead. But remember - by making your views tranparent you can worsen app's performance.
Since this has been around for a while I'll just throw some ideas out there.
You may be able to utilize the stringByEvaluatingJavaScriptFromString: method of the UIWebView class to manipulate the document object model if the UIWebView treats the loaded document as a page, but this method has some limitations.
Other than that, the only thing you really have left at your disposal is manipulating the view hierarchy to modify any subviews of the UIWebView, but there may not be anything for you manipulate if the UIWebView class renders the viewer directly rather than creating a hierarchy.
It looks like it is not possible to remove the border from a UIWebView but could you not use CGContextDrawPDFPage() as Apple show here: http://developer.apple.com/library/ios/#samplecode/ZoomingPDFViewer/Introduction/Intro.html
Try this,
self.webview.backgroundColor = [UIColor whiteColor];
for (UIView* subView in [self.webview subviews])
{
if ([subView isKindOfClass:[UIScrollView class]]) {
for (UIView* shadowView in [subView subviews])
{
if ([shadowView isKindOfClass:[UIImageView class]]) {
[shadowView setHidden:YES];
}
}
}
}
This may help you. :-)
You need a bunch of CoreAnimation magic:
- (void) hideShadowInLayer:(CALayer *) layer
{
for (CALayer *l in layer.sublayers) {
l.shadowOpacity = 0;
[self hideShadowInLayer:l];
}
}
- (void) hideShadows
{
[CATransaction begin];
[CATransaction setValue:(id) kCFBooleanTrue forKey:kCATransactionDisableActions];
[self hideShadowInLayer:webView.layer];
[CATransaction commit];
}
You need to perform hideShadows method somewhere AFTER loading your document and while you are scrolling it (I guess scrollViewDidScroll of webView.scrollView.delegate is a good place). You also need to include QuartzCore framework to your project.
What's going on here:
Any view uses something called layer for rendering. Layers can have its own hierarchy and every layer can have its own border and shadow, so the frame that annoying you is the shadow of one of them. Bad thing - UIWebView recreates it while scrolling - so you need to use this method constantly. And I guess shadowOpacity has a default animation attached to it, so you need CATransaction to disable it.

iphone sdk- UIAlertView button with image

can you please tell me if it is possible to use an uiimage view as uialertview button "text"?
i was unable to find the answer googling..
thanks a lot
Yes, it is possible, but I wouldn't recommend it. You'd have to run through the UIAlertView's subviews until you find one that is of the right class, I would assume UIButton, and add your UIImageView on top like this:
for (UIView *v in [myAlertView subviews]) {
if ([v isKindOfClass:[UIButton class]]) {
//IF I AM THE RIGHT BUTTON
[v addSubview:myUIImageView];
}
}
To determine the correct button, you might initially give it some odd text like "foobar5" and test each button to see if that is its text, and if so, remove the text and add the UIImageView.
You can use unicode characters, which are rendered as icons.
I described it here:
Adding Images to UIActionSheet buttons as in UIDocumentInteractionController

Can you tell UIWebView to use a white indicator style?

I'm running into a case where I have in-application HTML documentation that uses a dark background, but the default scroll indicator for UIWebView is getting lost in that background. The following is an example of this:
(source: sunsetlakesoftware.com)
With UIScrollView, which UIWebView resembles in its behavior, you can set the indicatorStyle property to UIScrollViewIndicatorStyleWhite, which results in the desired behavior:
(source: sunsetlakesoftware.com)
I can't seem to find a similar property in the exposed interface for UIWebView. Is there a CSS trick or other way to force the scroll indicator to a lighter style?
Starting iOS 5.0 onwards, one can now customize the scrolling behavior of the web view by accessing the 'scrollview' property to achieve the desired functionality:
webView.scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
If you do want to scan the subviews and attempt to gracefully fail if something changes in the future this currently works:
//set a white scroll bar
for (UIView *subview in [webView subviews]) {
if ([subview isKindOfClass:NSClassFromString(#"UIScroller")] || [subview isKindOfClass:NSClassFromString(#"UIScrollView")]) {
if ([subview respondsToSelector:#selector(setIndicatorStyle:)]) {
[(UIScrollView *)subview setIndicatorStyle:UIScrollViewIndicatorStyleWhite];
}
break;
}
}
Though things could still break in the future if setIndicatorStyle: changes to expect a non-enumerated value... but I doubt that would happen.
Scan the subviews and test for a UIScrollView. You can then programatically set the indicator.
There is no public API for this in the 2.x SDK. File a bug/case/radar asking for it in 3.0.