iOS Development Basics-Fragmentation 46

Source: Internet
Author: User

1: URL processing with Chinese

http://static.tripbe.com/videofiles/video/My selfie video. mp4nsstring *path  = (__bridge_transfer NSString *) Cfurlcreatestringbyreplacingpercentescapesusingencoding (NULL, (__bridge cfstringref) Model.mp4_url, CFSTR (""), Cfstringconvertnsstringencodingtoencoding (nsutf8stringencoding));

2: take webview height

-(void) Webviewdidfinishload: (UIWebView *) WebView {cgfloat height = [[WebView Stringbyevaluatingjavascriptfromstrin      g:@ "Document.body.offsetHeight"] floatvalue];      CGRect frame = webview.frame;  Webview.frame = CGRectMake (frame.origin.x, FRAME.ORIGIN.Y, frame.size.width, height); }
Another way to take advantage of KVO instance:-(void) viewdidload{//KVO, as an observer, as long as the property "Contentsize" Changes, the callback method inside will notify [_webview.scrollview Addobserver : Self forkeypath:@ "contentsize" Options:nskeyvalueobservingoptionnew Context:null];} callback Method-(void) Observevalueforkeypath: (NSString *) KeyPath Ofobject: (ID) object change: (nsdictionary *) Change context: ( void *) context{if (object = = _webview.scrollview && [keypath isequaltostring:@ "Contentsize"]) {//              To the maximum y-coordinate cgsize size = _webview.scrollview.contentsize; if (Size.Height > 568.0) {//occlusion ad _hidebottomimage = [[Uiimageview alloc] Initwithfr            Ame:cgrectmake (0, size.height-67, ScreenWidth, 67)];            _hidebottomimage.image = [UIImage imagenamed:@ "banner"];        [_webview.scrollview Addsubview:_hidebottomimage]; }} else {//Call the parent class method [Super Observevalueforkeypath:keypath Ofobject:object Change:change Context:    Context]; }}-(void) dealloc{//----> in ARC Environmentcan also call the Dealloc method, but do not need to write [super Dealloc]//Remove KVO, otherwise it will cause resource leakage [_webview.scrollview removeobserver:self forkeypath:@ "Conte Ntsize "];}

partial fillet problem of 3:uiview

UIView *view2 = [[UIView alloc] Initwithframe:cgrectmake (+)];view2.backgroundcolor = [Uicolor Redcolor]; [Self.view Addsubview:view2]; Uibezierpath *maskpath = [Uibezierpath bezierPathWithRoundedRect:view2.bounds byroundingcorners: Uirectcornerbottomleft | Uirectcornerbottomright Cornerradii:cgsizemake (10, 10)]; Cashapelayer *masklayer = [[Cashapelayer alloc] init];masklayer.frame = View2.bounds;masklayer.path = MaskPath.CGPath; View2.layer.mask = masklayer;//where, Byroundingcorners:uirectcornerbottomleft | The uirectcornerbottomright//specifies the corners that need to be rounded corners. The parameter is of type Uirectcorner, and the optional values are: * uirectcornertopleft* uirectcornertopright* uirectcornerbottomleft* uirectcornerbottomright* uirectcornerallcorners

4: Force app to exit directly

-(void) exitapplication {appdelegate *app = [UIApplication sharedapplication].delegate;    UIWindow *window = App.window;    [UIView animatewithduration:1.0f animations:^{window.alpha = 0;    } completion:^ (BOOL finished) {exit (0); }];}

5: Modify placeholder color and size

Textfield.placeholder = @ "Please enter user name";  [TextField setvalue:[uicolor Redcolor] forkeypath:@ "_placeholderlabel.textcolor"]; [TextField Setvalue:[uifont boldsystemfontofsize:16] forkeypath:@ "_placeholderlabel.font"];

6: Cancel the system's return gesture

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

7: Change webview font/ color

UIWebView set font size, color, font: UIWebView Some properties of the font cannot be set by their properties, but only through HTML code after the webview is loaded:

-(void) Webviewdidfinishload: (UIWebView *) WebView {nsstring *str = @ "document.getElementsByTagName (' body ') [0].style].      webkittextsizeadjust= ' 60% ' "; [WebView STRINGBYEVALUATINGJAVASCRIPTFROMSTRING:STR]; or add the following code nsstring *jsstring = [[NSString alloc] initwithformat:@ "DOCUMENT.BODY.STYLE.FONTSIZE=%F;   document.body.style.color=%@ ", Fontsize,fontcolor]; [WebView stringbyevaluatingjavascriptfromstring:jsstring];

8:webview Picture Adaptive Screen

-(void) Webviewdidfinishload: (UIWebView *) WebView {  NSString *js = @ "function Imgautofit () {      var IMGs = document. getElementsByTagName (' img ');      for (var i = 0; i < imgs.length; ++i) {        var img = imgs[i];           Img.style.maxWidth =%f;        }   } ";  JS = [NSString stringwithformat:js, [UIScreen mainscreen].bounds.size.width-20];   [WebView Stringbyevaluatingjavascriptfromstring:js];  [WebView stringbyevaluatingjavascriptfromstring:@ "Imgautofit ()"];}

The difference between 9:bool/bool/boolean/nscfboolean

10:nil/nil/null/nsnull differences

A, nil: general assignment to empty objects;

B, null: A value other than nil is generally assigned to a null value. such as SEL, etc.;

Give me a chestnut (good weight ~):

[Nsapp Beginsheet:sheet
Modalforwindow:mainwindow

Modaldelegate:nil//pointing to an object

Didendselector:null//pointing to a non object/class

Contextinfo:null]; Pointing to a non object/class

C, Nsnull:nsnull only one method: + (NSNULL *) null;

[NSNull NULL] is used to add a non-nil (representing the end of the list) to a null value in Nsarray and Nsdictionary.

Nsmutabledictionary *mutabledictionary = [nsmutabledictionary dictionary];mutabledictionary[@ "someKey"] = [NSNull NULL]; Sets value of NSNull singleton for ' Somekey ' NSLog (@ "Keys:%@", [Mutabledictionary AllKeys]); @[@ "Somekey"]

D, when sending a message to nil, return no, there will be no exception, the program will continue to execute;

You receive an exception when you send a message to an Nsnull object.

11: Sub-class implementation-isequal: and Hash

@interface person@property nsstring *name; @property nsdate *birthday;-(BOOL) Isequaltoperson: (person *) person;@ End@implementation person-(BOOL) Isequaltoperson: (person *) person {  if (!person) {    return NO;  }  BOOL haveequalnames = (!self.name &&!person.name) | | [Self.name IsEqualToString:person.name];  BOOL haveequalbirthdays = (!self.birthday &&!person.birthday) | | [Self.birthday IsEqualToDate:person.birthday];  return haveequalnames && haveequalbirthdays;} #pragma mark-nsobject-(BOOL) IsEqual: (ID) object {  if (self = = object) {    return YES;  }  if (![ Object Iskindofclass:[person class]] {    return NO;  }  return [self Isequaltoperson: (person *) object];} -(Nsuinteger) hash {  return [self.name hash] ^ [self.birthday hash];}

iOS Development Basics-Fragmentation 46

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.