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

第四次作业 #221

Open
wants to merge 5 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
647 changes: 647 additions & 0 deletions yxb144325004祁陈斌/NetMusic/NetMusic.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions yxb144325004祁陈斌/NetMusic/NetMusic/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// AppDelegate.h
// NetMusic
//
// Created by xsdlr on 14/12/1.
// Copyright (c) 2014年 xsdlr. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;


@end

53 changes: 53 additions & 0 deletions yxb144325004祁陈斌/NetMusic/NetMusic/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// AppDelegate.m
// NetMusic
//
// Created by xsdlr on 14/12/1.
// Copyright (c) 2014年 xsdlr. All rights reserved.
//

#import "AppDelegate.h"
#import "MainViewController.h"
#import "CRNavigationController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];
self.window.rootViewController = [[CRNavigationController alloc] initWithRootViewController: [[MainViewController alloc] init]];
[self.window makeKeyAndVisible];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="1000" verticalHuggingPriority="1000" image="launch" translatesAutoresizingMaskIntoConstraints="NO" id="JX8-l0-Tr8">
<rect key="frame" x="112" y="112" width="256" height="256"/>
<constraints>
<constraint firstAttribute="width" constant="256" id="DMn-fC-Hqz"/>
<constraint firstAttribute="height" constant="256" id="mAw-UL-adq"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="centerY" secondItem="JX8-l0-Tr8" secondAttribute="centerY" id="fAe-xg-4NI"/>
<constraint firstAttribute="centerX" secondItem="JX8-l0-Tr8" secondAttribute="centerX" id="iRu-Ix-GQp"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="695" y="423"/>
</view>
</objects>
<resources>
<image name="launch" width="256" height="256"/>
</resources>
</document>
49 changes: 49 additions & 0 deletions yxb144325004祁陈斌/NetMusic/NetMusic/BaseViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// BaseViewController.h
// NetMusic
//
// Created by xsdlr on 14/12/1.
// Copyright (c) 2014年 xsdlr. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface BaseViewController : UIViewController
@property (weak,nonatomic) UIColor *navigationBarBackgroundColor;
@property (weak,nonatomic) UIColor *navigationBarTitleColor;
/**
* 添加普通标题栏
*
* @param title 标题名称
* @param color 标题颜色
*/
- (void) addTitleViewByTitle: (NSString*) title color:(UIColor*) color;
/**
* 添加带图片的左侧按钮
*
* @param imageName 图片名
* @param selectedImageName 高亮图片名
*/
- (void) addLeftButtonByImage:(NSString*) imageName
selectedImageName:(NSString *) selectedImageName;
/**
* 添加带图片的右侧按钮
*
* @param imageName 图片名
* @param selectedImageName 高亮图片名
*/
- (void) addRightButtonByImage:(NSString*) imageName
selectedImageName:(NSString *) selectedImageName;
/**
* 添加带文字的左侧按钮
*
* @param title 按钮名称
*/
- (void) addLeftButtonByTitle:(NSString*) title;
/**
* 添加带文字的右侧按钮
*
* @param title 按钮名称
*/
- (void) addRightButtonByTitle:(NSString*) title;
@end
107 changes: 107 additions & 0 deletions yxb144325004祁陈斌/NetMusic/NetMusic/BaseViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// BaseViewController.m
// NetMusic
//
// Created by xsdlr on 14/12/1.
// Copyright (c) 2014年 xsdlr. All rights reserved.
//

#import "BaseViewController.h"
#import "UIButtonMake.h"

@interface BaseViewController ()
- (void) initLayout;
@end

@implementation BaseViewController

- (void)viewDidLoad {
[super viewDidLoad];
[self initLayout];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)setNavigationBarBackgroundColor:(UIColor *)navigationBarBackgroundColor {
_navigationBarBackgroundColor = navigationBarBackgroundColor;
self.navigationController.navigationBar.backgroundColor = _navigationBarBackgroundColor;
}

- (void)setNavigationBarTitleColor:(UIColor *)navigationBarTitleColor {
_navigationBarTitleColor = navigationBarTitleColor;
self.navigationController.navigationBar.barTintColor = _navigationBarTitleColor;
}

- (void)initLayout {
self.automaticallyAdjustsScrollViewInsets = false;
self.view.backgroundColor = [UIColor whiteColor];
// 设置状态栏字体颜色为白色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

- (UIBarButtonItem*) addButtonByImage:(NSString*) imageName selectedImageName:(NSString *) selectedImageName {
UIImage *image = [UIImage imageNamed:imageName];
UIImage *selectedImage = [UIImage imageNamed:selectedImageName];
UIButton *button = [UIButtonMake createWithImage:image
selectedimage:(UIImage *) selectedImage
target:self
action:@selector(leftButtonDealer:)
events:UIControlEventTouchUpInside];
UIView *subView = [[UIView alloc] initWithFrame:button.frame];
[subView addSubview:button];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView: subView];
return barButtonItem;
}

- (void)addLeftButtonByImage:(NSString *)imageName selectedImageName:(NSString *)selectedImageName {
self.navigationItem.leftBarButtonItem = [self addButtonByImage:imageName selectedImageName:selectedImageName];
}

- (void)addRightButtonByImage:(NSString *)imageName selectedImageName:(NSString *)selectedImageName {
self.navigationItem.rightBarButtonItem = [self addButtonByImage:imageName selectedImageName:selectedImageName];
}

- (UIBarButtonItem*) addButtonByTitle:(NSString*) title {
UIButton *button = [UIButtonMake createWithTitle:title width:50.0f height:44.0f target:self action:@selector(leftButtonDealer:) events:UIControlEventTouchUpInside];
UIView *subView = [[UIView alloc] initWithFrame:button.frame];
[subView addSubview:button];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:subView];
return barButtonItem;
}

- (void)addLeftButtonByTitle:(NSString *)title {
self.navigationItem.leftBarButtonItem = [self addButtonByTitle:title];
}

- (void)addRightButtonByTitle:(NSString *)title {
self.navigationItem.rightBarButtonItem = [self addButtonByTitle:title];
}

- (void) leftButtonDealer: (id)sender {
NSLog(@"点击导航栏左按钮");
}

- (void)addTitleViewByTitle:(NSString *)title color:(UIColor *)color {
UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0 , 100, 44)];
titleLabel.backgroundColor = [UIColor clearColor]; //设置Label背景透明
titleLabel.font = [UIFont boldSystemFontOfSize:20]; //设置文本字体与大小
titleLabel.textColor = color; //设置文本颜色
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = title;
self.navigationItem.titleView = titleLabel;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// CRNavigationBar.h
// CRNavigationControllerExample
//
// Created by Corey Roberts on 9/24/13.
// Copyright (c) 2013 SpacePyro Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import <UIKit/UIKit.h>

@interface CRNavigationBar : UINavigationBar

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// CRNavigationBar.m
// CRNavigationControllerExample
//
// Created by Corey Roberts on 9/24/13.
// Copyright (c) 2013 SpacePyro Inc. All rights reserved.
//

#import "CRNavigationBar.h"

@interface CRNavigationBar ()
@property (nonatomic, strong) CALayer *colorLayer;
@end

@implementation CRNavigationBar

static CGFloat const kDefaultColorLayerOpacity = 0.4f;
static CGFloat const kSpaceToCoverStatusBars = 20.0f;

- (void)setBarTintColor:(UIColor *)barTintColor {
[super setBarTintColor:barTintColor];

if (self.colorLayer == nil) {
self.colorLayer = [CALayer layer];
self.colorLayer.opacity = kDefaultColorLayerOpacity;
[self.layer addSublayer:self.colorLayer];
}

CGFloat red, green, blue, alpha;
[barTintColor getRed:&red green:&green blue:&blue alpha:&alpha];

CGFloat opacity = kDefaultColorLayerOpacity;

CGFloat minVal = MIN(MIN(red, green), blue);

if ([self convertValue:minVal withOpacity:opacity] < 0) {
opacity = [self minOpacityForValue:minVal];
}

self.colorLayer.opacity = opacity;

red = [self convertValue:red withOpacity:opacity];
green = [self convertValue:green withOpacity:opacity];
blue = [self convertValue:blue withOpacity:opacity];

red = MAX(MIN(1.0, red), 0);
green = MAX(MIN(1.0, green), 0);
blue = MAX(MIN(1.0, blue), 0);

self.colorLayer.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha].CGColor;
}

- (CGFloat)minOpacityForValue:(CGFloat)value
{
return (0.4 - 0.4 * value) / (0.6 * value + 0.4);
}

- (CGFloat)convertValue:(CGFloat)value withOpacity:(CGFloat)opacity
{
return 0.4 * value / opacity + 0.6 * value - 0.4 / opacity + 0.4;
}

- (void)layoutSubviews {
[super layoutSubviews];

if (self.colorLayer != nil) {
self.colorLayer.frame = CGRectMake(0, 0 - kSpaceToCoverStatusBars, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) + kSpaceToCoverStatusBars);

[self.layer insertSublayer:self.colorLayer atIndex:1];
}
}

- (void)displayColorLayer:(BOOL)display {
self.colorLayer.hidden = !display;
}

@end
Loading