Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simple textView Demo and Chinese support #37

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
459 changes: 459 additions & 0 deletions MarkDownDemo/MarkDownDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions MarkDownDemo/MarkDownDemo/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// AppDelegate.h
// MarkDownDemo
//
// Created by tangkunyin on 15/9/8.
// Copyright (c) 2015年 shuoit. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;


@end

37 changes: 37 additions & 0 deletions MarkDownDemo/MarkDownDemo/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// AppDelegate.m
// MarkDownDemo
//
// Created by tangkunyin on 15/9/8.
// Copyright (c) 2015年 shuoit. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor orangeColor];

ViewController *rootViewController = [[ViewController alloc] init];

self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];

return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {}

- (void)applicationDidEnterBackground:(UIApplication *)application {}

- (void)applicationWillEnterForeground:(UIApplication *)application {}

- (void)applicationDidBecomeActive:(UIApplication *)application {}

- (void)applicationWillTerminate:(UIApplication *)application {}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"images" : [
{
"orientation" : "portrait",
"idiom" : "ipad",
"minimum-system-version" : "7.0",
"extent" : "full-screen",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"minimum-system-version" : "7.0",
"extent" : "full-screen",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"minimum-system-version" : "7.0",
"extent" : "full-screen",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"minimum-system-version" : "7.0",
"subtype" : "retina4",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"minimum-system-version" : "7.0",
"extent" : "full-screen",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
43 changes: 43 additions & 0 deletions MarkDownDemo/MarkDownDemo/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>shuoit.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
22 changes: 22 additions & 0 deletions MarkDownDemo/MarkDownDemo/MdSource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
* italics *
** bold **
*** bold italic ***
~~ strikethrough ~~

# Header 1
## Header 2
### Header 3
#### Header 4
##### Header 5
###### Header 6

## 再来段中文试试看

Header 1
========

Header 2
--------

http://shuoit.net urls
[说IT] (http://shuoit.net "唐先森的技术博客")
15 changes: 15 additions & 0 deletions MarkDownDemo/MarkDownDemo/ViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// ViewController.h
// MarkDownDemo
//
// Created by tangkunyin on 15/9/8.
// Copyright (c) 2015年 shuoit. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@end

59 changes: 59 additions & 0 deletions MarkDownDemo/MarkDownDemo/ViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// ViewController.m
// MarkDownDemo
//
// Created by tangkunyin on 15/9/8.
// Copyright (c) 2015年 shuoit. All rights reserved.
//

#import "ViewController.h"
#import "NSAttributedStringMarkdownParser.h"

@interface ViewController ()
@property (nonatomic, strong) UITextView *textView;
@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

NSAttributedString *attributeString = [self parseMarkDownText:[self getSourceTextFromLocalFile]];

self.textView.attributedText = attributeString;

[self.view addSubview:self.textView];
}

- (NSString *)getSourceTextFromLocalFile
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MdSource.md" ofType:nil];
NSString *articleText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
return articleText;
}



- (NSAttributedString *)parseMarkDownText:(NSString *)sourceText
{
if (sourceText) {
NSAttributedStringMarkdownParser *parser = [[NSAttributedStringMarkdownParser alloc] init];
NSAttributedString *string = [parser attributedStringFromMarkdownString:sourceText];
return string;
}
return nil;
}

#pragma mark - getter
- (UITextView *)textView
{
if (_textView == nil) {
_textView = [[UITextView alloc] init];
_textView.editable = NO;
_textView.backgroundColor = [UIColor orangeColor];
_textView.frame = CGRectMake(0, 20, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));
}
return _textView;
}

@end
16 changes: 16 additions & 0 deletions MarkDownDemo/MarkDownDemo/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// main.m
// MarkDownDemo
//
// Created by tangkunyin on 15/9/8.
// Copyright (c) 2015年 shuoit. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Loading