分类 Objective-C 下的文章

Objective-C Learning Notes - UIWebView

在 iOS 应用中, Web 视图(UIWebView)是没有边框的 safari 窗口,可以将其加入应用程序并以编程方式进行控制. 通过使用这个类可以显示 HTML, 加载网页及支持缩放.

UIWebView 还可以用于显示如下文件:

  • HTML, 图像和 CSS

  • Word 文档(.doc/.docx)

  • Excel 电子表格(.xls/.xlsx)

  • Keynote 演示文稿(.key.zip)

  • Numbers 电子表格(.numbers.zip)

  • Pages 文档(.pages.zip)

  • PDF文档(.pdf)

  • PowerPoint 演示文档(.ppt/pptx)

- 阅读剩余部分 -

Objective-C Learning Notes - UISegmentControl

按钮栏

    可以结合使用索引和实例方法 titleForSegmentAtIndex 来获取每个分段的标题.要获取分段控件中当前选定的标题,可以使用以下代码段:

    [mySegment titleForSegmentAtIndex:mySegment.selectSegmentIndex];

动态实现:

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong,nonatomic)UISegmentedControl *mySegmentControl;
@end

- 阅读剩余部分 -

Objective-C Learning Notes - Second practice using UISlider and UISwitch

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *sliderLabel;
@property (weak, nonatomic) IBOutlet UISlider *mySlider;
@property (weak, nonatomic) IBOutlet UISwitch *leftSlider;
@property (weak, nonatomic) IBOutlet UISwitch *rightSlider;
- (IBAction)sliderChanged:(id)sender;
- (IBAction)switchChanged:(id)sender;
@end

- 阅读剩余部分 -

Objective-C Learning Notes - UISwitch (Rewrite)(坑)

重写 UISwitch 类以添加修改其文本信息的方法:

好讨厌一本书里面的样例程序各个编写习惯都不一样....

//  UISwitchCustom.h
#import <UIKit/UIKit.h>
/**
 添加一个名为 extended 的 category, 声明一下 UISwitch 的 setAlertnateColors 消息,否则在使用的时候会出现找不到该消息的警告.其实 setAlertnateColors 已经在 UISwitch 中实现,只是没u 头文件中公开而已,所以在此做一个声明...
 当调用setAlertnateColors:YES 时,UISwitch 的状态为"on"时显示为橙色.
 **/
@interface UISwitch (extended)
- (void) setAlertnateColors:(BOOL)boolean;
@end
//自定义 slider 类,方便存储数据而已(好像 wwwww
@interface _UISwitchSlider : UISlider
@end
//自定义 UISwitch 类并拓展可以修改按钮上面的文字方法
@interface UISwitchCustom : UISwitch
//设置左边的文字
- (void) setLeftLabelText:(NSString *)labelText
                     font:(UIFont *)labelFont
                    color:(UIColor *)labelColor;
//设置右边的文字
- (void) setRightLabelText:(NSString *)labelText
                      font:(UIFont *)labelFont
                     color:(UIColor *)labelColor;
//一个方便创建 Label 的方法而已,其实它不应该出现在这里的吧...
- (UILabel *)createLabelWithText:(NSString *)labelText
                            font:(UIFont *)labelFont
                           color:(UIColor *)labelColor;
@end

- 阅读剩余部分 -

Objective-C Learning Notes - UIImageView

UIImageView

创建方法

  • UIImageView *imageView1 = [[UIImageView alloc] init];

  • UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:(CGRect)];

  • UIImageView *imageView3 = [[UIImageView alloc] initWithImage:(UIImage *)];

  • UIImageView *imageView4 = [[UIImageView alloc] initWithImage:(UIImage *) highlightedImage:(UIImage *)];

  • UIImageView *imageView5 = [[UIImageView alloc] initWithCoder:(NSCoder *)];

- 阅读剩余部分 -