Learn more! A collection of iOS trivia

Learn more! A collection of iOS trivia

CAGradientLayer

The CAGradientLayer class is used to draw a color gradient on its background color to fill the entire shape of the layer, including rounded corners. This class inherits from the CALayer class and is very convenient to use.

Similar to the gradient processing in Quartz 2D, a gradient has a starting position (startPoint) and an ending position (endPoint). Between these two positions, we can specify a set of color values ​​(colors, elements are CGColorRef objects), which can be two or more, and each color value corresponds to a location (locations). In addition, gradients are divided into axial gradients and radial gradients.

Let's write an example to see the specific use of CAGradientLayer:

  1. CAGradientLayer *layer = [CAGradientLayer layer];
  2. layer.startPoint = (CGPoint){ 0 .5f, 0 .0f};
  3. layer.endPoint = (CGPoint){ 0 .5f, 1 .0f};
  4. layer.colors = [NSArray arrayWithObjects:(id)[UIColor blueColor].CGColor, (id)[UIColor redColor].CGColor, (id)[UIColor greenColor].CGColor, nil];
  5. layer.locations = @[ @0 .0f, @0 .6f, @1 .0f];
  6. layer.frame = self.view.layer.bounds;
  7. [self.view.layer insertSublayer:layer atIndex: 0 ];

refer to

CAGradientLayer Class Reference

Handling Ineligible Devices in Xcode

I changed to a new computer, installed Xcode 6.3, created a new certificate and profile, opened Xcode, and connected my phone. But then I found that the device was marked as Ineligible Devices and was not recognized. The situation is similar to the following picture:

The computer is trusted, and the certificates and profiles are OK. I tried restarting Xcode and reconnecting the phone several times, but it didn't work. I just can't select the device. *** I selected the device in Product->Destination. But I still can't select it in the toolbar. I'm so frustrated. Please help.

User comment: I changed the iOS SDK to iOS 7 and it was available, but then I ignored it. It was available again in iOS 8 SDK for unknown reasons...

Hide the cursor of UITextField after iOS 7

After the new project only supports iOS 7, many things become much simpler, just like hiding the cursor of UITextField, with a simple sentence:

  1. textFiled.tintColor = [UIColor clearColor];

Usually when we use UIPickerView as our UITextField's inputView, we need to hide the cursor. Of course, if you want to change the cursor color, you can do the same.

There is a legacy problem with this approach: usually when we use UIPickerView as the inputView of UITextField, we don't want to perform various menu operations (select all, copy, paste), but when we just want to set the tintColor of UITextField, we can still perform these operations, so additional processing is required. We can handle this problem like this: in textFieldShouldBeginEditing:, we set the userInteractionEnabled of UITextField to NO, and then in textFieldShouldEndEditing:, set this value back. As follows:

  1. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  2. textField.userInteractionEnabled = NO;
  3. return YES;
  4. }
  5. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
  6. textField.userInteractionEnabled = YES;
  7. return YES;
  8. }

That's it. Of course, this is just one way we are currently using. There are other methods, just google or stackoverflow.

Left alignment issue of Chinese text in UIAlertView after iOS 7

Before iOS 7, if we want to display the text in UIAlertView on the left, we can use the following code to handle it:

  1. for (UIView *view in alert.subviews) {
  2. if ([[view class ] isSubclassOfClass:[UILabel class ]]) {
  3. ((UILabel*)view).textAlignment = NSTextAlignmentLeft;
  4. }
  5. }

But unfortunately, after iOS 7, Apple doesn't allow us to do this. When we get the subviews of UIAlertView, we get an empty array and we can't get the label we want. What should we do? Three ways: tell the product manager and UED that this can't be implemented (of course, this will be despised, and people will say you are incompetent); write it yourself; find a third-party open source code. Hehe, but because of the tight schedule recently, I decided to tell them that it can't be implemented, haha. But I found an open source on github, Custom iOS AlertView, with a lot of stars. It looks good, I will study it carefully later.

<<:  5 Do's and 3 Don'ts in Code Comments

>>:  Why did Google and Apple develop their own programming languages?

Recommend

Hammer is going to make games: Has Luo found a new "sentiment"?

While Smartisan Technology was preparing for the ...

Tencent 360 Lenovo Xiaomi: Why choose them for Windows 10 distribution?

While the mobile Internet is swallowing up everyt...

What brand advantages are needed to use low-price strategies for marketing?

Many people believe that if the product has the s...

Double the battery life of your phone with just one piece of glass

When it comes to keeping smartphones and laptops ...

World Economic Forum: Digital Twin City Framework and Global Practice Report

The global digital twin market is booming. It is ...

Little Red Book Promotion Notes Marketing Strategy!

If you ask me which platform users enjoy watching...

NetEase Youdao Dictionary Pen 2.0 Review: Redefining the way to look up words

With the advancement of technology, more and more...

Service registration and discovery based on Zookeeper

background Most systems start with a single syste...

Marketing node reminder in May

April is coming to an end and May is approaching....