IOS Development Hundred Questions (9)

Source: Internet
Author: User

111. Why is it useless to set layer.bordercolor in IB?

I'm in IB by setting the runtime property of the UIView to get a rounded rectangle with a red border, as shown in:


However, the BorderColor property appears to be invalid and the border cannot be displayed.

Layer.bordercolor is a Cgcolorref property, and the Runtime property's color palette can only be uicolor properties, so you can't set bordercolor in IB, but only through code settings.

112. Can I use DLOG macros and ALOG macros in Swift?

Complex macros used in C and objective-c cannot be used in swift. A complex macro is a macro other than a constant definition, and contains a function macro with parentheses. We can define global functions instead of:
Func DLog (message:string, filename:string = __file__, function:string =__function__, line:int = __line__) {

If debug==1 {

println ("[\ (filename.lastpathcomponent): \ (line)] \ (function)-\ (message)")

}

}

113. The enumeration in O-C is not available in Swift?

Error: Enum case pattern cannot match values of the Non-enum type ' enum name '

Up to Beta 5,swift can only map enumeration classes that are defined using Ns_enum macros in O-c. Therefore, the O-C enumeration defined for all TypeDef enum methods requires the Ns_num definition to be re-used:

typedef enum {

Chinamobile = 0,//MNC 00 02 07

chinaunicom,//MNC 01 06

chinatelecom,//MNC 03 04

Chinatietong,//MNC 20

Unknown

} carriername;

114. Can I use #ifdef macros in Swift?

#if/#else/#endif can be used in Swift:

#if DEBUG

Let A = 2

#else

Let A = 3

#endif

However, the DEBUG symbol must be defined in the other Swift Flags:


115. What is the difference between Textfieldshouldreturn method return YES or NO?

Returning YES will trigger automatic text correction and automatic initial capitalization (the so-called default behavior in Apple Docs), and returning no is not.

116, how to change the Uitextview line height?

First set the Uitextview layoumanager.delegate:

TextView.layoutManager.delegate = self; You ' ll need to declare

Then in implementing the Delegate method:

-(CGFloat) LayoutManager: (Nslayoutmanager *) Layoutmanagerlinespacingafterglyphatindex: (NSUInteger) Glyphindexwithproposedlinefragmentrect: (cgrect) rect

{

return 4; This is the line spacing

}

117, modify the minimum height of the Uitextview

No matter how you modify the frame height of the Uitextview in IB, it is useless. The minimum height of a uitextview is calculated by its content, and its minimum height is equal to the single line height. So on iOS 7 you can modify the minimum height by setting its Textcontainerinset (iOS 6 is Contentinset):

if (Nsfoundationversionnumber >nsfoundationversionnumber_ios_6_1) {

Self.textcontainerinset =uiedgeinsetsmake (4, 10, 4, 10);

} else {

Self.contentinset =uiedgeinsetsmake (4, 10, 4, 10);

}

117, after inserting the picture (nstextattachment) The nsattribtuedstring font is changed to be small

Insert Picture before font:


After inserting the picture:


This is because nstextattachment is inserted when inserted as above, which results in three properties being modified: Font, Baseline, Nssuperscriptattributename.

So after inserting the picture, you need to change these 3 values to the default (light modified font does not work):

[Mutableattrstring addattributes:

@{nsfontattributename:[uifontsystemfontofsize:16], (ID) kctsuperscriptattributename:@0, Nsbaselineoffsetattributename:@0} range:nsmakerange (0,mutableattrstring.length)];

Note Nssuperscriptattributename is not valid in IOS. It is therefore necessary to replace it with Coretext Kctsuperscriptattributename.

118. How to press two Viewcontroller into the navigation controller at once?

Just this:

[Viewcontroller1.navigationcontroller PushViewController:viewController2animated:NO];

[Viewcontroller2.navigationcontroller PushViewController:viewController3animated:YES];

The first push without animation, the second push when the draw, so users will feel that only push a viewcontroller, and actually you push two.

119, statistics the entire project code line number

Open the terminal and use the CD command to navigate to the directory where the project resides, and then call the following name to count the number of lines and totals for each source code file:

Find. "("-name "*.m"-or-name "*.mm"-or-name "*.cpp"-or-name "*.h"-or-name "*.rss" ")"-print | Xargs wc-l

where-name "*.M" represents a file with an. m extension. The commands to count both Java files and XML files are:

Find. "("-name "*.java" ")"-print | Xargs wc-l

Find. "("-name "*.xml" ")"-print | Xargs wc-l


120, how to reduce the delay of Requiregesturerecognizertofail method?

Requiregesturerecognizertofail is generally used to distinguish between clicks and double-click recognition. Let's say you have two gestures, one click and you don't want to be recognized as a double-click when the user double-clicks, you can use the following code:

UITapGestureRecognizer *doubletapgesturerecognizer =[[uitapgesturerecognizer Alloc]

Initwithtarget:self Action: @selector (Handledoubletap:)];

doubletapgesturerecognizer.numberoftapsrequired = 2;

[Self addgesturerecognizer:doubletapgesturerecognizer];

UITapGestureRecognizer *singletapgesturerecognizer =[[uitapgesturerecognizer Alloc] initwithtarget:selfaction:@ Selector (HANDLESINGLETAP:)];

singletapgesturerecognizer.numberoftapsrequired = 1;

[Singletapgesturerecognizer requiregesturerecognizertofail: Doubletapgesturerecognizer];

[Selfaddgesturerecognizer:singletapgesturerecognizer];

However, this method has a fatal disadvantage, because each click must first double-tap recognition, and to wait for double-click recognition failed to do the processing, resulting in a delay each click, generally this time will be 0.35 seconds. Although 0.35 seconds is short, the user can feel a noticeable delay. So we need to overload the Tapgesturerecognizer to reduce this delay:

#import <UIKit/UIGestureRecognizerSubclass.h>

#define Uishort_tap_max_delay 0.25

@interface Uishorttapgesturerecognizer:uitapgesturerecognizer

@property (nonatomic,assign) float maxdelay;

@end

#import "UIShortTapGestureRecognizer.h"

@implementation Uishorttapgesturerecognizer

-(Instancetype) Initwithtarget: (nsobject*) Target action: (SEL) selector{

Self=[super InitWithTarget:targetaction:selector];

if (self) {

Self.maxdelay=uishort_tap_max_delay;

}

return self;

}

-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event

{

[Super TouchesBegan:toucheswithEvent:event];

Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (Self.maxdelay * nsec_per_sec)), Dispatch_get_main_queue ( ), ^

{

After 0.1 seconds, the gesture recognition fails.

if (Self.state!=uigesturerecognizerstaterecognized)

{

Self.state= uigesturerecognizerstatefailed;

}

});

}

@end

It is now possible to set its Maxdelay property after instantiating Uishorttapgesturerecognizer. Note that this value is not less than 0.2 seconds (the user must be very fast, otherwise the double-click action cannot be completed), and the best is 0.25.


IOS Development Hundred Questions (9)

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.