├── .gitignore ├── Images ├── ba-refresh-black.png ├── ba-refresh-black@2x.png ├── ba-sequence-item-active.png ├── ba-sequence-item-passive.png ├── ba-sequence-item-active@2x.png └── ba-sequence-item-passive@2x.png ├── BaseAppKit.h ├── BaseAppKitCore.h ├── BaseAppKitUI.h ├── UIView+BACookie.h ├── BAToggleItem.h ├── BASimpleReusableView.h ├── BAMeshViewCell+Owner.h ├── BASwitchCell.h ├── BAJSONViewController.h ├── BAWebViewController.h ├── NSString+BACoding.h ├── BATextViewController.h ├── BAImageLoader.h ├── BAXMLLoader.h ├── UITableView+BALoading.h ├── BAScrollViewProxyDelegate.h ├── BANetwork.h ├── BAEditableCell.h ├── BAProgressLayer.h ├── BANetworkActivity.h ├── BAXMLLoader.m ├── BAXMLParserBase.h ├── BAActivityView.h ├── UINavigationController+BATransitions.h ├── BAProgressView.h ├── BAImageLoader.m ├── UIView+BACookie.m ├── BARuntime.h ├── BAKeyboardTracker.h ├── BASimpleReusableView.m ├── BAToggleItemLabel.h ├── BAMeshViewCell.h ├── BAViewsCache.h ├── BARemoteImageToggleItem.h ├── BAGradientView.h ├── BAToggleItemImage.h ├── BALabel.h ├── BACommon.h ├── UITableView+BALoading.m ├── BANetworkActivity.m ├── NSDate+BADays.h ├── NSString+BACoding.m ├── BAWebViewController.m ├── BARemoteImageView.h ├── BAJSONLoader.h ├── UINavigationController+BATransitions.m ├── BASwitchCell.m ├── BASequenceControl.h ├── BAXMLParserBase.m ├── BANetwork.m ├── BASeparatedTableProvider.h ├── BAPager.h ├── BARefreshHeaderView.h ├── BAPersistentCache.h ├── BAMeshViewCell.m ├── BACustomPageControl.h ├── BANetworkReachability.h ├── BAGroupedPageControl.h ├── BAToggleBar.h ├── BAViewsCache.m ├── BAEditableCell.m ├── BATextViewController.m ├── BAToggleItemImage.m ├── BAPageControl.h ├── BARemoteJSON.h ├── BADataLoader.h ├── BAActivityView.m ├── NSDate+BADays.m ├── BAToggleItemLabel.m ├── BAProgressView.m ├── BARemoteImageToggleItem.m ├── BAGradientView.m ├── BAJSONLoader.m ├── BAScrollViewProxyDelegate.m ├── BAProgressLayer.m ├── BARemoteImageView.m ├── BARuntime.m └── BALabel.m /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .svn 3 | -------------------------------------------------------------------------------- /Images/ba-refresh-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dimzzy/BaseAppKit/HEAD/Images/ba-refresh-black.png -------------------------------------------------------------------------------- /Images/ba-refresh-black@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dimzzy/BaseAppKit/HEAD/Images/ba-refresh-black@2x.png -------------------------------------------------------------------------------- /Images/ba-sequence-item-active.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dimzzy/BaseAppKit/HEAD/Images/ba-sequence-item-active.png -------------------------------------------------------------------------------- /Images/ba-sequence-item-passive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dimzzy/BaseAppKit/HEAD/Images/ba-sequence-item-passive.png -------------------------------------------------------------------------------- /Images/ba-sequence-item-active@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dimzzy/BaseAppKit/HEAD/Images/ba-sequence-item-active@2x.png -------------------------------------------------------------------------------- /Images/ba-sequence-item-passive@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dimzzy/BaseAppKit/HEAD/Images/ba-sequence-item-passive@2x.png -------------------------------------------------------------------------------- /BaseAppKit.h: -------------------------------------------------------------------------------- 1 | #ifndef __BASEAPPKIT__ 2 | #define __BASEAPPKIT__ 3 | 4 | #include 5 | #include 6 | 7 | #endif // __BASEAPPKIT__ 8 | -------------------------------------------------------------------------------- /BaseAppKitCore.h: -------------------------------------------------------------------------------- 1 | #ifndef __BASEAPPKITCORE__ 2 | #define __BASEAPPKITCORE__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #endif // __BASEAPPKITCORE__ 19 | -------------------------------------------------------------------------------- /BaseAppKitUI.h: -------------------------------------------------------------------------------- 1 | #ifndef __BASEAPPKITUI__ 2 | #define __BASEAPPKITUI__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #endif // __BASEAPPKITUI__ 39 | -------------------------------------------------------------------------------- /UIView+BACookie.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface UIView (UIView_BACookie) 32 | 33 | @property(retain) id cookie; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /BAToggleItem.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @protocol BAToggleItem 32 | 33 | @property(nonatomic, assign) BOOL selected; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /BASimpleReusableView.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAViewsCache.h" 31 | 32 | @interface BASimpleReusableView : UIView 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /BAMeshViewCell+Owner.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAMeshViewCell.h" 30 | 31 | @interface BAMeshViewCell () 32 | 33 | @property(nonatomic, retain) NSIndexPath *indexPath; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /BASwitchCell.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BASwitchCell : UITableViewCell 32 | 33 | @property(nonatomic, retain) UISwitch *switchView; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /BAJSONViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BAJSONViewController : UITableViewController 32 | 33 | @property(nonatomic, retain) id JSONValue; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /BAWebViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BAWebViewController : UIViewController 32 | 33 | @property(nonatomic, readonly) UIWebView *webView; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /NSString+BACoding.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface NSString (BACoding) 32 | 33 | - (NSString *)MD5Hash; 34 | + (NSString *)stringWithUUID; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /BATextViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BATextViewController : UIViewController 32 | 33 | @property(nonatomic, readonly) UITextView *textView; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /BAImageLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BADataLoader.h" 31 | 32 | @interface BAImageLoader : BADataLoader 33 | 34 | @property(nonatomic, readonly) UIImage *image; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /BAXMLLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BADataLoader.h" 30 | #import "BAXMLParserBase.h" 31 | 32 | @interface BAXMLLoader : BADataLoader 33 | 34 | @property(nonatomic, retain) BAXMLParserBase *parser; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /UITableView+BALoading.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface UITableView (BALoading) 32 | 33 | - (UITableViewCell *)dequeueOrLoadReusableCellWithClass:(Class)type loaded:(BOOL *)loaded; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /BAScrollViewProxyDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BAScrollViewProxyDelegate : NSObject 32 | 33 | @property(nonatomic, assign) id delegate; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /BANetwork.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BANetwork : NSObject 32 | 33 | + (BOOL)loadingURL:(NSURL *)URL; 34 | + (void)startLoadingURL:(NSURL *)URL; 35 | + (void)finishLoadingURL:(NSURL *)URL; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /BAEditableCell.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BAEditableCell : UITableViewCell 32 | 33 | @property(nonatomic, retain) UITextField *textField; 34 | @property(nonatomic, assign) CGFloat textFieldX; 35 | 36 | + (void)stopEditing:(UITableView *)tableView; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /BAProgressLayer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BAProgressLayer : CALayer 32 | 33 | @property(nonatomic, assign) float progress; // 0..1 34 | @property(nonatomic, assign) BOOL failed; 35 | @property(nonatomic, assign) CGColorRef progressColor; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /BANetworkActivity.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import 31 | 32 | @interface BANetworkActivity : NSObject { 33 | @private 34 | NSUInteger _level; 35 | } 36 | 37 | + (BANetworkActivity *)networkActivity; 38 | - (void)start; 39 | - (void)stop; 40 | - (void)stopAll; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /BAXMLLoader.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAXMLLoader.h" 30 | 31 | @implementation BAXMLLoader 32 | 33 | @synthesize parser = _parser; 34 | 35 | - (void)dealloc { 36 | [_parser release]; 37 | [super dealloc]; 38 | } 39 | 40 | - (BOOL)prepareData:(NSData *)data { 41 | return ![_parser parse:data]; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /BAXMLParserBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BAXMLParserBase : NSObject { 32 | @private 33 | NSMutableString *_bufferText; 34 | } 35 | 36 | - (void)enableBuffer; 37 | - (void)disableBuffer; 38 | - (NSString *)bufferText; 39 | 40 | - (NSError *)parse:(NSData *)data; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /BAActivityView.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BAActivityView : UIView { 32 | @private 33 | UIActivityIndicatorView *_indicatorView; 34 | UILabel *_descriptionLabel; 35 | } 36 | 37 | @property(nonatomic, readonly) UIActivityIndicatorView *indicatorView; 38 | @property(nonatomic, readonly) UILabel *descriptionLabel; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /UINavigationController+BATransitions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface UINavigationController (BATransitions) 32 | 33 | - (void)pushViewController:(UIViewController *)controller withTransition:(UIViewAnimationTransition)transition; 34 | - (UIViewController *)popViewControllerWithTransition:(UIViewAnimationTransition)transition; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /BAProgressView.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BAProgressView : UIView { 32 | @private 33 | float _progress; 34 | BOOL _failed; 35 | UIColor *_progressColor; 36 | } 37 | 38 | @property(nonatomic, assign) float progress; // 0..1 39 | @property(nonatomic, assign) BOOL failed; 40 | @property(nonatomic, retain) UIColor *progressColor; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /BAImageLoader.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAImageLoader.h" 30 | 31 | @implementation BAImageLoader 32 | 33 | @synthesize image = _image; 34 | 35 | - (void)dealloc { 36 | [_image release]; 37 | [super dealloc]; 38 | } 39 | 40 | - (BOOL)prepareData:(NSData *)data { 41 | [_image release]; 42 | _image = [[UIImage alloc] initWithData:data]; 43 | return !!_image; 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /UIView+BACookie.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "UIView+BACookie.h" 30 | #import 31 | 32 | static char BAViewCookieKey; 33 | 34 | @implementation UIView (UIView_BACookie) 35 | 36 | - cookie { 37 | return objc_getAssociatedObject(self, &BAViewCookieKey); 38 | } 39 | 40 | - (void)setCookie:cookie { 41 | objc_setAssociatedObject(self, &BAViewCookieKey, cookie, OBJC_ASSOCIATION_RETAIN); 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /BARuntime.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BARuntime : NSObject 32 | 33 | + (id)parseJSONData:(NSData *)data error:(NSError **)error; 34 | + (NSData *)serializeJSONToData:(id)JSONValue error:(NSError **)error; 35 | + (NSString *)serializeJSONToString:(id)JSONValue error:(NSError **)error; 36 | + (NSString *)serializeJSONToString:(id)JSONValue formatted:(BOOL)formatted error:(NSError **)error; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /BAKeyboardTracker.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | // Based on TPKeyboardAvoiding by Michael Tyson; refactored to support composition over inheritance. 30 | 31 | #import 32 | 33 | @interface BAKeyboardTracker : NSObject { 34 | @private 35 | CGRect _priorFrame; 36 | UIScrollView *_scrollView; 37 | } 38 | 39 | @property(nonatomic, retain) UIScrollView *scrollView; 40 | 41 | - (void)scrollViewFrameDidChange; 42 | - (CGFloat)bottomSpacing; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /BASimpleReusableView.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BASimpleReusableView.h" 30 | 31 | @implementation BASimpleReusableView 32 | 33 | @synthesize reuseIdentifier = _reuseIdentifier; 34 | 35 | - (void)dealloc { 36 | [_reuseIdentifier release]; 37 | [super dealloc]; 38 | } 39 | 40 | - (void)didMoveToWindow { 41 | self.window ? 42 | [[BAViewsCache sharedCache] removeReusableView:self] : 43 | [[BAViewsCache sharedCache] enqueueReusableView:self]; 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /BAToggleItemLabel.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAToggleItem.h" 31 | 32 | @interface BAToggleItemLabel : UILabel { 33 | @private 34 | BOOL _selected; 35 | UIColor *_normalTextColor; 36 | } 37 | 38 | @property(nonatomic, assign) BOOL selected; 39 | @property(nonatomic, retain) UIColor *selectedBackgroundColor; 40 | @property(nonatomic, retain) UIColor *selectedTextColor; 41 | @property(nonatomic, assign) UIEdgeInsets insets; 42 | @property(nonatomic, assign) CGFloat padding; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /BAMeshViewCell.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @interface BAMeshViewCell : UIView 32 | 33 | - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier; 34 | - (void)prepareForReuse; 35 | @property(nonatomic,readonly,copy) NSString *reuseIdentifier; 36 | 37 | @property(nonatomic,readonly,retain) UIView *contentView; 38 | 39 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated; 40 | @property(nonatomic,getter=isSelected) BOOL selected; 41 | @property(nonatomic,getter=isHighlighted) BOOL highlighted; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /BAViewsCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #include 30 | 31 | @protocol BAReusableView 32 | 33 | @property(copy) NSString *reuseIdentifier; 34 | 35 | @end 36 | 37 | 38 | @interface BAViewsCache : NSObject 39 | 40 | @property(readonly) NSUInteger capacityPerType; 41 | 42 | + (BAViewsCache *)sharedCache; 43 | 44 | - (UIView *)dequeueReusableViewWithIdentifier:(NSString *)reuseIdentifier; 45 | - (void)enqueueReusableView:(UIView *)view; 46 | - (void)removeReusableView:(UIView *)view; 47 | - (void)clear; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /BARemoteImageToggleItem.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAToggleItem.h" 31 | #import "BARemoteImageView.h" 32 | 33 | @interface BARemoteImageToggleItem : UIView { 34 | @private 35 | BARemoteImageView *_imageView; 36 | UIEdgeInsets _imageInsets; 37 | BOOL _selected; 38 | UIColor *_selectedOutlineColor; 39 | } 40 | 41 | @property(nonatomic, readonly) BARemoteImageView *imageView; 42 | @property(nonatomic, assign) UIEdgeInsets imageInsets; 43 | @property(nonatomic, assign) BOOL selected; 44 | @property(nonatomic, retain) UIColor *selectedOutlineColor; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /BAGradientView.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | typedef enum { 32 | BAGradientViewDirectionDown, 33 | BAGradientViewDirectionUp, 34 | BAGradientViewDirectionRight, 35 | BAGradientViewDirectionLeft 36 | } BAGradientViewDirection; 37 | 38 | @interface BAGradientView : UIView { 39 | @private 40 | UIColor *_startColor; 41 | UIColor *_endColor; 42 | BAGradientViewDirection _gradientDirection; 43 | } 44 | 45 | @property(nonatomic, retain) UIColor *startColor; 46 | @property(nonatomic, retain) UIColor *endColor; 47 | @property(nonatomic, assign) BAGradientViewDirection gradientDirection; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /BAToggleItemImage.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAToggleItem.h" 31 | 32 | @interface BAToggleItemImage : UIView { 33 | @private 34 | UIImage *_image; 35 | NSUInteger _imagePadding; 36 | BOOL _selected; 37 | UIColor *_selectedBackgroundColor; 38 | UIColor *_selectedOutlineColor; 39 | } 40 | 41 | @property(nonatomic, retain) UIImage *image; 42 | @property(nonatomic, assign) NSUInteger imagePadding; 43 | @property(nonatomic, assign) BOOL selected; 44 | @property(nonatomic, retain) UIColor *selectedBackgroundColor; 45 | @property(nonatomic, retain) UIColor *selectedOutlineColor; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /BALabel.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BACommon.h" 31 | 32 | typedef enum { 33 | BALabelBezelNone = 0, 34 | BALabelBezelRound, 35 | BALabelBezelRoundSolid 36 | } BALabelBezel; 37 | 38 | @interface BALabel : UILabel 39 | 40 | @property(nonatomic, assign) UIEdgeInsets textInsets; 41 | @property(nonatomic, assign) BAVerticalAlignment verticalAlignment; 42 | @property(nonatomic, assign) BALabelBezel bezel; 43 | @property(nonatomic, assign) CGFloat bezelLineWidth; 44 | @property(nonatomic, retain) UIColor *bezelColor; 45 | 46 | - (void)sizeToFitInWidth; 47 | - (void)sizeToFitInWidthMaxHeight:(CGFloat)maxHeight; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /BACommon.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | #define BAAlert(TITLE,MSG) [[[[UIAlertView alloc] initWithTitle:(TITLE) \ 32 | message:(MSG) \ 33 | delegate:nil \ 34 | cancelButtonTitle:@"OK" \ 35 | otherButtonTitles:nil] autorelease] show] 36 | 37 | #define UIColorFromRGB(RGB) [UIColor colorWithRed:((float)((RGB & 0xFF0000) >> 16)) / 255.0 \ 38 | green:((float)((RGB & 0xFF00) >> 8)) / 255.0 \ 39 | blue:((float)((RGB & 0xFF))) / 255.0 \ 40 | alpha:1.0] 41 | 42 | typedef enum { 43 | BAVerticalAlignmentCenter = 0, 44 | BAVerticalAlignmentTop, 45 | BAVerticalAlignmentBottom 46 | } BAVerticalAlignment; 47 | -------------------------------------------------------------------------------- /UITableView+BALoading.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "UITableView+BALoading.h" 30 | 31 | @implementation UITableView (BALoading) 32 | 33 | - (UITableViewCell *)dequeueOrLoadReusableCellWithClass:(Class)type loaded:(BOOL *)loaded { 34 | assert(type); 35 | NSString *identifier = NSStringFromClass(type); 36 | UITableViewCell *cell = [self dequeueReusableCellWithIdentifier:identifier]; 37 | if (loaded) { 38 | *loaded = !cell; 39 | } 40 | if (!cell) { 41 | NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:identifier owner:self options:nil]; 42 | for (id nib in nibs) { 43 | if ([nib isKindOfClass:type]) { 44 | cell = nib; 45 | break; 46 | } 47 | } 48 | } 49 | return cell; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /BANetworkActivity.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BANetworkActivity.h" 30 | 31 | @implementation BANetworkActivity 32 | 33 | + (BANetworkActivity *)networkActivity { 34 | static BANetworkActivity *instance; 35 | if (!instance) { 36 | instance = [[BANetworkActivity alloc] init]; 37 | } 38 | return instance; 39 | } 40 | 41 | - (void)start { 42 | if (++_level == 1) { 43 | [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; 44 | } 45 | } 46 | 47 | - (void)stop { 48 | if (_level == 0) { 49 | return; 50 | } 51 | if (--_level == 0) { 52 | [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 53 | } 54 | } 55 | 56 | - (void)stopAll { 57 | _level = 0; 58 | [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /NSDate+BADays.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | // Day is an NSDate object at this time, which allows NSDate objects to be used as hash keys 32 | #define kBADayHour 12 33 | 34 | @interface NSDate (BADays) 35 | 36 | - (NSDate *)nextDay; 37 | - (NSDate *)nextDayInCalendar:(NSCalendar *)calendar; 38 | - (NSDate *)prevDay; 39 | - (NSDate *)prevDayInCalendar:(NSCalendar *)calendar; 40 | - (NSDate *)currDay; 41 | - (NSDate *)currDayInCalendar:(NSCalendar *)calendar; 42 | - (BOOL)sameDay:(NSDate *)anotherDate; 43 | - (BOOL)sameDay:(NSDate *)anotherDate inCalendar:(NSCalendar *)calendar; 44 | - (NSInteger)daysSinceNow; 45 | - (NSInteger)daysSinceNowInCalendar:(NSCalendar *)calendar; 46 | - (NSInteger)currHour; 47 | - (NSInteger)currHourInCalendar:(NSCalendar *)calendar; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /NSString+BACoding.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "NSString+BACoding.h" 30 | 31 | #include 32 | 33 | @implementation NSString (BACoding) 34 | 35 | - (NSString *)MD5Hash { 36 | const char *cStr = [self UTF8String]; 37 | unsigned char result[16]; 38 | CC_MD5(cStr, strlen(cStr), result); 39 | return [NSString stringWithFormat: 40 | @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", 41 | result[0], result[1], result[2], result[3], 42 | result[4], result[5], result[6], result[7], 43 | result[8], result[9], result[10], result[11], 44 | result[12], result[13], result[14], result[15]]; 45 | } 46 | 47 | + (NSString *)stringWithUUID { 48 | CFUUIDRef uuid = CFUUIDCreate(NULL); 49 | CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid); 50 | CFRelease(uuid); 51 | return [(NSString *)uuidStr autorelease]; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /BAWebViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAWebViewController.h" 30 | 31 | @interface BAWebViewController () 32 | 33 | @end 34 | 35 | @implementation BAWebViewController { 36 | UIWebView *_webView; 37 | } 38 | 39 | - (void)dealloc { 40 | [_webView release]; 41 | [super dealloc]; 42 | } 43 | 44 | - (UIWebView *)webView { 45 | if (!_webView) { 46 | _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; 47 | _webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 48 | } 49 | return _webView; 50 | } 51 | 52 | - (void)viewDidLoad { 53 | [super viewDidLoad]; 54 | if (!self.webView.window) { 55 | self.webView.frame = self.view.bounds; 56 | [self.view addSubview:self.webView]; 57 | } 58 | } 59 | 60 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 61 | return YES; 62 | } 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /BARemoteImageView.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAImageLoader.h" 31 | 32 | @class BARemoteImageView; 33 | 34 | @protocol BARemoteImageViewDelegate 35 | 36 | @optional 37 | - (void)remoteImageView:(BARemoteImageView *)imageView touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 38 | - (void)remoteImageView:(BARemoteImageView *)imageView touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; 39 | - (void)remoteImageView:(BARemoteImageView *)imageView touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; 40 | - (void)remoteImageViewDidLoad:(BARemoteImageView *)imageView; 41 | - (void)remoteImageView:(BARemoteImageView *)imageView didFailWithError:(NSError *)error; 42 | 43 | @end 44 | 45 | @interface BARemoteImageView : UIImageView 46 | 47 | @property(nonatomic, retain) NSURL *remoteImageURL; 48 | @property(nonatomic, assign) BOOL animateImageUpdate; 49 | @property(nonatomic, assign) id delegate; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /BAJSONLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BADataLoader.h" 30 | 31 | @interface BAJSONLoader : BADataLoader 32 | 33 | @property(nonatomic, readonly) id JSONValue; 34 | 35 | + (id)parseJSONData:(NSData *)data error:(NSError **)error; 36 | 37 | + (NSString *)stringFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key; 38 | + (NSArray *)arrayFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key; 39 | + (NSDictionary *)dictionaryFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key; 40 | + (BOOL)boolFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key; 41 | + (BOOL)boolFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key defaultValue:(BOOL)defaultValue; 42 | + (int)intFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key; 43 | + (int)intFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key defaultValue:(int)defaultValue; 44 | + (double)doubleFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key; 45 | + (double)doubleFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key defaultValue:(int)defaultValue; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /UINavigationController+BATransitions.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "UINavigationController+BATransitions.h" 30 | 31 | @implementation UINavigationController (BATransitions) 32 | 33 | - (void)pushViewController:(UIViewController *)controller withTransition:(UIViewAnimationTransition)transition { 34 | [UIView beginAnimations:nil context:NULL]; 35 | [self pushViewController:controller animated:NO]; 36 | [UIView setAnimationDuration:0.5]; 37 | [UIView setAnimationBeginsFromCurrentState:YES]; 38 | [UIView setAnimationTransition:transition forView:self.view cache:YES]; 39 | [UIView commitAnimations]; 40 | } 41 | 42 | - (UIViewController *)popViewControllerWithTransition:(UIViewAnimationTransition)transition { 43 | [UIView beginAnimations:nil context:NULL]; 44 | UIViewController *controller = [self popViewControllerAnimated:NO]; 45 | [UIView setAnimationDuration:0.5]; 46 | [UIView setAnimationBeginsFromCurrentState:YES]; 47 | [UIView setAnimationTransition:transition forView:self.view cache:YES]; 48 | [UIView commitAnimations]; 49 | return controller; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /BASwitchCell.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BASwitchCell.h" 30 | 31 | @implementation BASwitchCell 32 | 33 | @synthesize switchView; 34 | 35 | - (void)dealloc { 36 | self.switchView = nil; 37 | [super dealloc]; 38 | } 39 | 40 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 41 | if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { 42 | self.selectionStyle = UITableViewCellSelectionStyleNone; 43 | self.switchView = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease]; 44 | [self.contentView addSubview:self.switchView]; 45 | } 46 | return self; 47 | } 48 | 49 | - (void)layoutSubviews { 50 | [super layoutSubviews]; 51 | const CGFloat width = self.contentView.bounds.size.width; 52 | const CGFloat height = self.contentView.bounds.size.height; 53 | const CGFloat switchWidth = self.switchView.bounds.size.width; 54 | const CGFloat switchHeight = self.switchView.bounds.size.height; 55 | const CGFloat spacing = self.textLabel.frame.origin.x; 56 | self.switchView.frame = CGRectMake(width - spacing - switchWidth, (height - switchHeight) / 2, switchWidth, switchHeight); 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /BASequenceControl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | @class UISegmentedControl; 32 | 33 | @interface BASequenceControl : UIControl 34 | 35 | @property(nonatomic, retain) UIImage *activeSegmentImage; 36 | @property(nonatomic, retain) UIImage *passiveSegmentImage; 37 | @property(nonatomic, assign) CGFloat leftMargin; 38 | @property(nonatomic, assign) CGFloat rightMargin; 39 | @property(nonatomic, assign) CGFloat overlapWidth; 40 | @property(nonatomic, retain) UIFont *titleFont; 41 | @property(nonatomic, retain) UIColor *activeTitleColor; 42 | @property(nonatomic, retain) UIColor *passiveTitleColor; 43 | 44 | @property(nonatomic, readonly) NSUInteger numberOfSegments; 45 | @property(nonatomic) NSInteger selectedSegmentIndex; 46 | 47 | - (void)addSegmentWithTitle:(NSString *)title animated:(BOOL)animated; 48 | - (void)insertSegmentWithTitle:(NSString *)title atIndex:(NSUInteger)segment animated:(BOOL)animated; 49 | - (void)removeSegmentAtIndex:(NSUInteger)segment animated:(BOOL)animated; 50 | - (void)removeAllSegments; 51 | - (void)setTitle:(NSString *)title forSegmentAtIndex:(NSUInteger)segment; 52 | - (NSString *)titleForSegmentAtIndex:(NSUInteger)segment; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /BAXMLParserBase.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAXMLParserBase.h" 30 | 31 | @implementation BAXMLParserBase 32 | 33 | - (void)dealloc { 34 | [_bufferText release]; 35 | [super dealloc]; 36 | } 37 | 38 | - (NSError *)parse:(NSData *)data { 39 | NSXMLParser *parser = [[[NSXMLParser alloc] initWithData:data] autorelease]; 40 | [parser setShouldProcessNamespaces:NO]; 41 | [parser setShouldReportNamespacePrefixes:NO]; 42 | [parser setShouldResolveExternalEntities:NO]; 43 | parser.delegate = self; 44 | [parser parse]; 45 | return [parser parserError]; 46 | } 47 | 48 | - (void)enableBuffer { 49 | [_bufferText release]; 50 | _bufferText = [[NSMutableString alloc] init]; 51 | } 52 | 53 | - (void)disableBuffer { 54 | [_bufferText release]; 55 | _bufferText = nil; 56 | } 57 | 58 | - (NSString *)bufferText { 59 | return _bufferText ? [_bufferText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : nil; 60 | } 61 | 62 | - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { 63 | if (_bufferText) { 64 | [_bufferText appendString:string]; 65 | } 66 | } 67 | 68 | - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { 69 | NSString *text = [[NSString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding]; 70 | [self parser:parser foundCharacters:text]; 71 | [text release]; 72 | } 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /BANetwork.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BANetwork.h" 30 | 31 | @implementation BANetwork 32 | 33 | + (NSMutableDictionary *)loadingURLs { 34 | static NSMutableDictionary *BALoadingURLs; // URL -> NSNumber of connections 35 | if (!BALoadingURLs) { 36 | BALoadingURLs = [[NSMutableDictionary alloc] init]; 37 | } 38 | return BALoadingURLs; 39 | } 40 | 41 | + (BOOL)loadingURL:(NSURL *)URL { 42 | return URL ? !![[self loadingURLs] objectForKey:URL] : NO; 43 | } 44 | 45 | + (void)startLoadingURL:(NSURL *)URL { 46 | if (!URL) { 47 | return; 48 | } 49 | NSNumber *count = [[self loadingURLs] objectForKey:URL]; 50 | if (count) { 51 | count = [NSNumber numberWithUnsignedInteger:([count unsignedIntegerValue] + 1)]; 52 | } else { 53 | count = [NSNumber numberWithUnsignedInteger:1]; 54 | } 55 | [[self loadingURLs] setObject:count forKey:URL]; 56 | } 57 | 58 | + (void)finishLoadingURL:(NSURL *)URL { 59 | if (!URL) { 60 | return; 61 | } 62 | NSNumber *count = [[self loadingURLs] objectForKey:URL]; 63 | if (!count) { 64 | NSLog(@"BANetwork: connection was not started %@", URL); 65 | return; 66 | } 67 | if ([count unsignedIntegerValue] == 1) { 68 | [[self loadingURLs] removeObjectForKey:URL]; 69 | } else { 70 | count = [NSNumber numberWithUnsignedInteger:([count unsignedIntegerValue] - 1)]; 71 | [[self loadingURLs] setObject:count forKey:URL]; 72 | } 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /BASeparatedTableProvider.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAScrollViewProxyDelegate.h" 31 | 32 | enum { 33 | BACellSeparatorPositionNone = 0, 34 | BACellSeparatorPositionTop = 1 << 0, 35 | BACellSeparatorPositionBottom = 1 << 1 36 | }; 37 | 38 | typedef NSUInteger BACellSeparatorPositions; 39 | 40 | 41 | @protocol BASeparatedTableProviderDelegate 42 | 43 | - (BACellSeparatorPositions)tableView:(UITableView *)tableView separatorPositionsForRow:(NSIndexPath *)indexPath; 44 | - (UITableViewCell *)tableView:(UITableView *)tableView topSeparatorCellForRowAtIndexPath:(NSIndexPath *)indexPath; 45 | - (UITableViewCell *)tableView:(UITableView *)tableView bottomSeparatorCellForRowAtIndexPath:(NSIndexPath *)indexPath; 46 | - (CGFloat)tableView:(UITableView *)tableView heightForTopSeparatorRowAtIndexPath:(NSIndexPath *)indexPath; 47 | - (CGFloat)tableView:(UITableView *)tableView heightForBottomSeparatorRowAtIndexPath:(NSIndexPath *)indexPath; 48 | 49 | @end 50 | 51 | 52 | @interface BASeparatedTableProvider : BAScrollViewProxyDelegate 53 | 54 | @property(nonatomic, assign) id delegate; 55 | 56 | - (NSIndexPath *)separatedIndexPathForIndexPath:(NSIndexPath *)indexPath; 57 | - (NSArray *)separatedIndexPathsForIndexPaths:(NSArray *)indexPaths; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /BAPager.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAScrollViewProxyDelegate.h" 31 | 32 | @class BAPager; 33 | 34 | 35 | @protocol BAPagerDelegate 36 | 37 | // Create or reuse a view that will serve as a page; similar to tableView:cellForRowAtIndexPath: of table's data source 38 | - (UIView *)pager:(BAPager *)pager pageAtIndex:(NSInteger)index; 39 | 40 | @optional 41 | 42 | // Index at which page will be inserted in scroll view; 0 if not implemented 43 | // You could use it to control z-order of the pages 44 | - (NSInteger)pager:(BAPager *)pager orderOfPageAtIndex:(NSInteger)index; 45 | 46 | // Called when pager removes the page; good place to update your controller for the page 47 | - (void)pager:(BAPager *)pager dropPageAtIndex:(NSInteger)index; 48 | 49 | // Update current page indicators or what you have 50 | - (void)pager:(BAPager *)pager currentPageDidChangeTo:(NSInteger)index; 51 | 52 | @end 53 | 54 | 55 | @interface BAPager : BAScrollViewProxyDelegate 56 | 57 | @property(nonatomic, retain) UIScrollView *scrollView; 58 | @property(nonatomic, assign) NSUInteger numberOfPages; 59 | @property(nonatomic, assign) NSInteger currentPageIndex; 60 | @property(nonatomic, assign) id delegate; 61 | 62 | // Similar to reloadData of table view 63 | - (void)reloadPages; 64 | 65 | // You should call this method when scroll view bounds change, typically after rotation 66 | - (void)layoutPages; 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /BARefreshHeaderView.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | // Based heavily on https://github.com/enormego/EGOTableViewPullRefresh project. 30 | // Made control more clean and customizable. 31 | 32 | #import 33 | #import 34 | 35 | @class BARefreshHeaderView; 36 | 37 | 38 | @protocol BARefreshHeaderDelegate 39 | 40 | - (void)refreshHeaderDidTriggerRefresh:(BARefreshHeaderView *)view; 41 | - (BOOL)refreshHeaderDataSourceLoading:(BARefreshHeaderView *)view; 42 | 43 | @optional 44 | - (NSDate *)refreshHeaderDataSourceLastUpdated:(BARefreshHeaderView *)view; 45 | 46 | @end 47 | 48 | 49 | typedef enum { 50 | BARefreshHeaderStatePulling = 0, 51 | BARefreshHeaderStateIdle, 52 | BARefreshHeaderStateLoading, 53 | } BARefreshHeaderState; 54 | 55 | @interface BARefreshHeaderView : UIView 56 | 57 | @property(nonatomic, copy) NSString *errorText; 58 | @property(nonatomic, readonly) UILabel *lastUpdatedLabel; 59 | @property(nonatomic, readonly) UILabel *statusLabel; 60 | @property(nonatomic, readonly) CALayer *arrowImageLayer; 61 | @property(nonatomic, readonly) UIActivityIndicatorView *activityView; 62 | @property(nonatomic, assign) id delegate; 63 | 64 | - (void)refreshLastUpdatedDate; 65 | - (void)dataSourceDidStartLoading:(UIScrollView *)scrollView; 66 | - (void)dataSourceDidFinishLoading:(UIScrollView *)scrollView; 67 | - (void)dataSourceDidFail:(UIScrollView *)scrollView; 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /BAPersistentCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import 31 | 32 | #define kBAPersistentCacheRetainInterval (60 * 60 * 24 * 7) 33 | 34 | @protocol BAPersistencePolicy 35 | 36 | - (BOOL)staleContentAtPath:(NSString *)path; 37 | 38 | @end 39 | 40 | 41 | @interface BAPersistentCache : NSObject { 42 | @private 43 | NSString *_path; 44 | NSMutableDictionary *_policiesByKeyHashes; 45 | id _defaultPolicy; 46 | } 47 | 48 | @property(nonatomic, readonly) NSString *path; 49 | @property(nonatomic, retain) id defaultPolicy; 50 | 51 | + (BAPersistentCache *)persistentCache; 52 | + (id)keepForeverPolicy; 53 | + (id)keepForSomeTimePolicy:(NSTimeInterval)timeInterval; 54 | 55 | - (id)initWithPath:(NSString *)path; 56 | - (void)flush; 57 | - (NSDate *)modificationDateForKey:(NSString *)key; 58 | 59 | - (id)policyForKey:(NSString *)key; 60 | - (void)setPolicy:(id)policy forKey:(NSString *)key; 61 | 62 | - (BOOL)hasDataForKey:(NSString *)key; 63 | - (NSData *)dataForKey:(NSString *)key; 64 | - (void)setData:(NSData *)data forKey:(NSString *)key; 65 | - (void)clearDataForKey:(NSString *)key; 66 | 67 | - (id)objectForKey:(NSString *)key; 68 | - (void)setObject:(id)object forKey:(NSString *)key; 69 | 70 | - (UIImage *)imageForKey:(NSString *)key; 71 | - (void)setImage:(UIImage *)image forKey:(NSString *)key; 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /BAMeshViewCell.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAMeshViewCell.h" 30 | #import "BAMeshViewCell+Owner.h" 31 | 32 | @implementation BAMeshViewCell { 33 | @private 34 | BOOL _highlighted; 35 | BOOL _selected; 36 | UIView *_contentView; 37 | } 38 | 39 | @synthesize reuseIdentifier = _reuseIdentifier; 40 | @synthesize indexPath = _indexPath; 41 | 42 | - (void)dealloc { 43 | [_contentView release]; 44 | [_reuseIdentifier release]; 45 | [_indexPath release]; 46 | [super dealloc]; 47 | } 48 | 49 | - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier { 50 | if ((self = [super init])) { 51 | _reuseIdentifier = [reuseIdentifier copy]; 52 | } 53 | return self; 54 | } 55 | 56 | - (void)prepareForReuse { 57 | } 58 | 59 | - (UIView *)contentView { 60 | if (!_contentView) { 61 | _contentView = [[UIView alloc] init]; 62 | _contentView.frame = self.bounds; 63 | _contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 64 | [self addSubview:_contentView]; 65 | } 66 | return _contentView; 67 | } 68 | 69 | - (BOOL)isSelected { 70 | return _selected; 71 | } 72 | 73 | - (void)setSelected:(BOOL)selected { 74 | [self setSelected:selected animated:NO]; 75 | } 76 | 77 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 78 | _selected = selected; 79 | } 80 | 81 | - (BOOL)isHighlighted { 82 | return _highlighted; 83 | } 84 | 85 | - (void)setHighlighted:(BOOL)highlighted { 86 | _highlighted = highlighted; 87 | } 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /BACustomPageControl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAPageControl.h" 31 | 32 | @interface BACustomPageControl : UIControl 33 | 34 | @property(nonatomic) NSInteger numberOfPages; // default is 0 35 | @property(nonatomic) NSInteger currentPage; // default is 0. value pinned to 0..numberOfPages-1 36 | @property(nonatomic) BOOL hidesForSinglePage; // hide the the indicator if there is only one page. default is NO 37 | @property(nonatomic) BOOL defersCurrentPageDisplay; // if set, clicking to a new page won't update the currently 38 | // displayed page until -updateCurrentPageDisplay is called. 39 | // default is NO 40 | 41 | @property(nonatomic, assign) CGFloat unitSpacing; // distance between dots 42 | 43 | @property(nonatomic, retain) UIImage *activeImage; 44 | @property(nonatomic, retain) UIImage *inactiveImage; 45 | 46 | @property(nonatomic, assign) BAPageControlAlignment alignment; 47 | 48 | @property(nonatomic, assign) CGFloat inset; // for left/right aligned modes 49 | 50 | - (void)updateCurrentPageDisplay; // update page display to match the currentPage. 51 | // ignored if defersCurrentPageDisplay is NO. 52 | // setting the page value directly will update immediately 53 | 54 | - (CGSize)sizeForNumberOfPages:(NSInteger)pageCount; // returns minimum size required to display dots for given page count. 55 | // can be used to size control if page count could change 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /BANetworkReachability.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | // Based on Reachability sample project 30 | 31 | #import 32 | #import 33 | #import 34 | 35 | extern NSString * const BANetworkReachabilityDidChangeNotification; 36 | 37 | typedef enum { 38 | BANetworkNotReachable = 0, 39 | BANetworkReachableViaWiFi, 40 | BANetworkReachableViaWWAN 41 | } BANetworkStatus; 42 | 43 | @interface BANetworkReachability : NSObject 44 | 45 | // Use to check the reachability of a particular host name. 46 | + (BANetworkReachability *)reachabilityWithHostName:(NSString *)hostName; 47 | 48 | // Use to check the reachability of a particular IP address. 49 | + (BANetworkReachability *)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress; 50 | 51 | // Checks whether the default route is available. 52 | // Should be used by applications that do not connect to a particular host. 53 | + (BANetworkReachability *)reachabilityForInternetConnection; 54 | 55 | // Checks whether a local wifi connection is available. 56 | + (BANetworkReachability *)reachabilityForLocalWiFi; 57 | 58 | // Start listening for reachability notifications on the current run loop. 59 | - (BOOL)start; 60 | 61 | // Stop listening for reachability notifications on the current run loop. 62 | - (void)stop; 63 | 64 | @property(nonatomic, readonly) BANetworkStatus currentStatus; 65 | 66 | // WWAN may be available, but not active until a connection has been established. 67 | // WiFi may require a connection for VPN on Demand. 68 | @property(nonatomic, readonly) BOOL connectionRequired; 69 | 70 | - (SCNetworkReachabilityFlags)flags; 71 | 72 | - (NSString *)flagsString; 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /BAGroupedPageControl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAPageControl.h" 31 | 32 | typedef enum { 33 | BAGroupedPageControlModeDots = 0, // like system control 34 | BAGroupedPageControlModeBlocks, // squares instead of dots 35 | } BAGroupedPageControlMode; 36 | 37 | @interface BAGroupedPageControl : UIControl 38 | 39 | @property(nonatomic) NSInteger numberOfPages; // default is 0 40 | @property(nonatomic) NSInteger currentPage; // default is 0. value pinned to 0..numberOfPages-1 41 | @property(nonatomic) BOOL hidesForSinglePage; // hide the the indicator if there is only one page. default is NO 42 | @property(nonatomic) BOOL defersCurrentPageDisplay; // if set, clicking to a new page won't update the currently 43 | // displayed page until -updateCurrentPageDisplay is called. 44 | // default is NO 45 | 46 | @property(nonatomic, retain) UIColor *activeColor; // default is white 47 | @property(nonatomic, retain) UIColor *inactiveColor; // default is semitransparent active color 48 | 49 | @property(nonatomic, assign) BAGroupedPageControlMode primaryMode; // dots is default 50 | @property(nonatomic, assign) BAPageControlAlignment alignment; 51 | 52 | @property(nonatomic, assign) CGFloat inset; // for left/right aligned modes 53 | 54 | - (void)updateCurrentPageDisplay; // update page display to match the currentPage. 55 | // ignored if defersCurrentPageDisplay is NO. 56 | // setting the page value directly will update immediately 57 | 58 | - (CGSize)sizeForNumberOfPages:(NSInteger)pageCount; // returns minimum size required to display dots for given page count. 59 | // can be used to size control if page count could change 60 | 61 | @property(nonatomic, assign) NSUInteger pagesPerGroup; 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /BAToggleBar.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAToggleItem.h" 31 | 32 | typedef enum { 33 | // BAToggleBarTailStateToggleAnimated, 34 | BAToggleBarTailStateToggle, 35 | BAToggleBarTailStateHidden, 36 | BAToggleBarTailStateVisible 37 | } BAToggleBarTailState; 38 | 39 | 40 | @class BAToggleBar; 41 | 42 | 43 | @protocol BAToggleBarDelegate 44 | 45 | - (void)toggleBar:(BAToggleBar *)toggleBar didSelectItem:(id)item atIndex:(NSInteger)index; 46 | @optional 47 | - (UIView *)toggleBar:(BAToggleBar *)toggleBar viewForItem:(id)item atIndex:(NSInteger)index; 48 | - (UIView *)toggleBarSeparatorView:(BAToggleBar *)toggleBar; 49 | 50 | @end 51 | 52 | 53 | @interface BAToggleBar : UIView { 54 | UIScrollView *_scrollView; 55 | UIImageView *_leftTailView; 56 | BAToggleBarTailState _leftTailState; 57 | BOOL _leftTailHidden; 58 | UIImageView *_rightTailView; 59 | BAToggleBarTailState _rightTailState; 60 | BOOL _rightTailHidden; 61 | NSMutableArray *_itemViews; // [UIView] 62 | NSMutableArray *_items; 63 | NSInteger _selectedItemIndex; 64 | } 65 | 66 | @property(nonatomic, assign) BOOL centered; 67 | @property(nonatomic, assign) CGFloat spacing; 68 | @property(nonatomic, assign) BAToggleBarTailState leftTailState; 69 | @property(nonatomic, assign) BAToggleBarTailState rightTailState; 70 | @property(nonatomic, retain) UIImage *leftTailImage; 71 | @property(nonatomic, retain) UIImage *rightTailImage; 72 | @property(nonatomic, copy) NSArray *items; 73 | @property(nonatomic, assign) NSInteger selectedItemIndex; 74 | @property(nonatomic, assign) IBOutlet id delegate; 75 | 76 | - (void)setSelectedItemIndex:(NSInteger)selectedItemIndex revealingItem:(BOOL)revealingItem; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /BAViewsCache.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAViewsCache.h" 30 | 31 | @implementation BAViewsCache { 32 | NSMutableDictionary *_allViews; // reuseIdentifier -> NSMutableArray:UIView 33 | NSUInteger _capacityPerType; 34 | } 35 | 36 | @synthesize capacityPerType = _capacityPerType; 37 | 38 | - (id)init { 39 | if ((self = [super init])) { 40 | _allViews = [[NSMutableDictionary alloc] init]; 41 | _capacityPerType = 8; 42 | } 43 | return self; 44 | } 45 | 46 | + (BAViewsCache *)sharedCache { 47 | static BAViewsCache *cache; 48 | if (!cache) { 49 | cache = [[BAViewsCache alloc] init]; 50 | } 51 | return cache; 52 | } 53 | 54 | - (UIView *)dequeueReusableViewWithIdentifier:(NSString *)reuseIdentifier { 55 | if (!reuseIdentifier) { 56 | return nil; 57 | } 58 | NSMutableArray *views = [_allViews objectForKey:reuseIdentifier]; 59 | UIView *view = [views lastObject]; 60 | if (view) { 61 | [[view retain] autorelease]; 62 | [views removeLastObject]; 63 | return view; 64 | } 65 | return nil; 66 | } 67 | 68 | - (void)enqueueReusableView:(UIView *)view { 69 | if (![view reuseIdentifier]) { 70 | return; 71 | } 72 | NSMutableArray *views = [_allViews objectForKey:[view reuseIdentifier]]; 73 | if (views) { 74 | if ([views count] < self.capacityPerType) { 75 | [views addObject:view]; 76 | } 77 | } else { 78 | views = [NSMutableArray arrayWithObject:view]; 79 | [_allViews setObject:views forKey:[view reuseIdentifier]]; 80 | } 81 | } 82 | 83 | - (void)removeReusableView:(UIView *)view { 84 | if (![view reuseIdentifier]) { 85 | return; 86 | } 87 | NSMutableArray *views = [_allViews objectForKey:[view reuseIdentifier]]; 88 | if (views) { 89 | [views removeObjectIdenticalTo:view]; 90 | } 91 | } 92 | 93 | - (void)clear { 94 | [_allViews removeAllObjects]; 95 | } 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /BAEditableCell.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAEditableCell.h" 30 | 31 | static const CGFloat kTextFieldDefaultX = 120; 32 | 33 | @implementation BAEditableCell 34 | 35 | @synthesize textField, textFieldX; 36 | 37 | - (void)dealloc { 38 | self.textField = nil; 39 | [super dealloc]; 40 | } 41 | 42 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 43 | if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { 44 | self.selectionStyle = UITableViewCellSelectionStyleNone; 45 | self.textField = [[[UITextField alloc] initWithFrame:CGRectZero] autorelease]; 46 | self.textField.autoresizingMask = self.detailTextLabel.autoresizingMask; 47 | self.textField.font = [UIFont systemFontOfSize:17]; 48 | self.textField.textColor = self.detailTextLabel.textColor; 49 | [self.contentView addSubview:self.textField]; 50 | } 51 | return self; 52 | } 53 | 54 | - (void)layoutSubviews { 55 | [super layoutSubviews]; 56 | const CGFloat width = self.contentView.bounds.size.width; 57 | const CGFloat height = self.contentView.bounds.size.height; 58 | const CGFloat textX = self.textFieldX > 0 ? self.textFieldX : kTextFieldDefaultX; 59 | const CGFloat textHeight = self.textLabel.bounds.size.height; 60 | const CGFloat spacing = self.textLabel.frame.origin.x; 61 | self.textField.frame = CGRectMake(spacing + textX, (height - textHeight) / 2, 62 | (width - textX - spacing - spacing), textHeight); 63 | } 64 | 65 | + (void)stopEditing:(UITableView *)tableView { 66 | NSArray *cells = [[[tableView visibleCells] copy] autorelease]; 67 | if ([cells count] == 0) { 68 | return; 69 | } 70 | for (UITableViewCell *cell in cells) { 71 | if ([cell isKindOfClass:[BAEditableCell class]]) { 72 | BAEditableCell *editableCell = (BAEditableCell *)cell; 73 | [editableCell.textField resignFirstResponder]; 74 | } 75 | } 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /BATextViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BATextViewController.h" 30 | #import "BAWebViewController.h" 31 | 32 | @interface BATextViewController () 33 | 34 | @end 35 | 36 | @implementation BATextViewController { 37 | UITextView *_textView; 38 | } 39 | 40 | - (void)dealloc { 41 | [_textView release]; 42 | [super dealloc]; 43 | } 44 | 45 | - (UITextView *)textView { 46 | if (!_textView) { 47 | _textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; 48 | _textView.editable = NO; 49 | _textView.font = [UIFont systemFontOfSize:13]; 50 | _textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 51 | } 52 | return _textView; 53 | } 54 | 55 | - (void)viewDidLoad { 56 | [super viewDidLoad]; 57 | if (!self.textView.window) { 58 | self.textView.frame = self.view.bounds; 59 | [self.view addSubview:self.textView]; 60 | } 61 | } 62 | 63 | - (NSURL *)textURL { 64 | NSString *t = self.textView.text; 65 | if (![t hasPrefix:@"http://"] && ![t hasPrefix:@"https://"]) { 66 | return nil; 67 | } 68 | return [NSURL URLWithString:t]; 69 | } 70 | 71 | - (void)viewWillAppear:(BOOL)animated { 72 | [super viewWillAppear:animated]; 73 | self.navigationItem.rightBarButtonItem = nil; 74 | NSURL *URL = [self textURL]; 75 | if (URL) { 76 | self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction 77 | target:self 78 | action:@selector(openURL)] autorelease]; 79 | } 80 | } 81 | 82 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 83 | return YES; 84 | } 85 | 86 | - (void)openURL { 87 | NSURL *URL = [self textURL]; 88 | if (URL) { 89 | BAWebViewController *controller = [[[BAWebViewController alloc] init] autorelease]; 90 | [controller.webView loadRequest:[NSURLRequest requestWithURL:URL 91 | cachePolicy:NSURLRequestReloadIgnoringLocalCacheData 92 | timeoutInterval:60]]; 93 | [self.navigationController pushViewController:controller animated:YES]; 94 | } 95 | } 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /BAToggleItemImage.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAToggleItemImage.h" 31 | 32 | @implementation BAToggleItemImage 33 | 34 | @synthesize image = _image; 35 | @synthesize imagePadding = _imagePadding; 36 | @synthesize selectedBackgroundColor = _selectedBackgroundColor; 37 | @synthesize selectedOutlineColor = _selectedOutlineColor; 38 | 39 | - (void)dealloc { 40 | [_image release]; 41 | [_selectedBackgroundColor release]; 42 | [_selectedOutlineColor release]; 43 | [super dealloc]; 44 | } 45 | 46 | - (CGSize)sizeThatFits:(CGSize)size { 47 | CGSize viewSize; 48 | viewSize.width = viewSize.height = 0; 49 | if (self.image) { 50 | viewSize = self.image.size; 51 | } 52 | return CGSizeMake(viewSize.width + self.imagePadding, viewSize.height + self.imagePadding); 53 | } 54 | 55 | - (void)drawRect:(CGRect)rect { 56 | if (self.selected) { 57 | if (self.selectedBackgroundColor) { 58 | [self.selectedBackgroundColor set]; 59 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 60 | UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectInset(self.bounds, 0.5, 0.5) 61 | cornerRadius:5]; 62 | CGContextAddPath(ctx, path.CGPath); 63 | CGContextFillPath(ctx); 64 | } 65 | if (self.selectedOutlineColor) { 66 | [self.selectedOutlineColor set]; 67 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 68 | CGContextSetLineWidth(ctx, 1); 69 | UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectInset(self.bounds, 0.5, 0.5) 70 | cornerRadius:8]; 71 | CGContextAddPath(ctx, path.CGPath); 72 | CGContextStrokePath(ctx); 73 | } 74 | } 75 | if (self.image) { 76 | CGSize viewSize = self.bounds.size; 77 | CGSize imageSize = self.image.size; 78 | [self.image drawAtPoint:CGPointMake((viewSize.width - imageSize.width) / 2, 79 | (viewSize.height - imageSize.height) / 2)]; 80 | } 81 | } 82 | 83 | - (BOOL)selected { 84 | return _selected; 85 | } 86 | 87 | - (void)setSelected:(BOOL)selected { 88 | if (_selected == selected) { 89 | return; 90 | } 91 | _selected = selected; 92 | [self setNeedsDisplay]; 93 | } 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /BAPageControl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | 31 | typedef enum { 32 | BAPageControlModeDots = 0, // like system control 33 | BAPageControlModeBlocks, // squares instead of dots 34 | BAPageControlModeProgress, // rectangular progress bar with round corners 35 | BAPageControlModeBlock, // rectangular progress bar 36 | BAPageControlModePill // bordered progress bar with round corners 37 | } BAPageControlMode; 38 | 39 | typedef enum { 40 | BAPageControlAlignmentCenter, // default 41 | BAPageControlAlignmentLeft, 42 | BAPageControlAlignmentRight 43 | } BAPageControlAlignment; 44 | 45 | @interface BAPageControl : UIControl 46 | 47 | @property(nonatomic) NSInteger numberOfPages; // default is 0 48 | @property(nonatomic) NSInteger currentPage; // default is 0. value pinned to 0..numberOfPages-1 49 | @property(nonatomic) BOOL hidesForSinglePage; // hide the the indicator if there is only one page. default is NO 50 | @property(nonatomic) BOOL defersCurrentPageDisplay; // if set, clicking to a new page won't update the currently 51 | // displayed page until -updateCurrentPageDisplay is called. 52 | // default is NO 53 | 54 | @property(nonatomic, retain) UIColor *activeColor; // default is white 55 | @property(nonatomic, retain) UIColor *inactiveColor; // default is semitransparent active color 56 | 57 | @property(nonatomic, assign) BAPageControlMode primaryMode; // dots is default 58 | @property(nonatomic, assign) BAPageControlMode fitMode; // progress is default; used if primary mode is dots or blocks 59 | // and they don't fit in bounds (too many pages); 60 | // in most cases you want this to be progress, block or pill 61 | @property(nonatomic, readonly) BAPageControlMode displayMode; // primary or fit mode depending on bounds and pages count 62 | 63 | @property(nonatomic, assign) BAPageControlAlignment alignment; 64 | 65 | @property(nonatomic, assign) CGFloat inset; // for progress bar modes and left/right aligned modes 66 | 67 | - (void)updateCurrentPageDisplay; // update page display to match the currentPage. 68 | // ignored if defersCurrentPageDisplay is NO. 69 | // setting the page value directly will update immediately 70 | 71 | - (CGSize)sizeForNumberOfPages:(NSInteger)pageCount; // returns minimum size required to display dots for given page count. 72 | // can be used to size control if page count could change 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /BARemoteJSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | // You are supposed to make a subclass of BARemoteJSON for each endpoint of your backend 30 | // and override -remoteJSON:requestWithRPCString: method that creates requests for RPC strings. 31 | // It's also recommended to add descriptive methods that pack their arguments and call 32 | // the generic -invokeMethod:withParameters:completion method to define a meaningful backend API. 33 | 34 | #import 35 | #import "BADataLoader.h" 36 | 37 | typedef enum { 38 | BARemoteJSONParseError = -32700, 39 | BARemoteJSONInvalidRequest = -32600, 40 | BARemoteJSONMethodNotFound = -32601, 41 | BARemoteJSONInvalidParams = -32602, 42 | BARemoteJSONInternalError = -32603 43 | } BARemoteJSONErrorCode; 44 | 45 | extern NSInteger const BARemoteJSONMinErrorCode; 46 | extern NSInteger const BARemoteJSONMaxErrorCode; 47 | 48 | extern NSString * const BARemoteJSONErrorDomain; 49 | extern NSString * const BARemoteJSONErrorDataKey; 50 | 51 | // Normally backend replies with some result and no errors (nils). 52 | // If a paticular method fails to execute then it's callback is called once with methodError. 53 | // All other errors like connection failure, invalid JSON or invalid response stucture are passed as 54 | // invocationError to all callbacks in the batch and they could be called several times. 55 | // IOW when we can identify method which has failed then error is passed as methodError 56 | // otherwise error passed as invocationError (to all callbacks in the batch). 57 | typedef void (^BARemoteJSONCallback)(id result, NSError *methodError, NSError *invocationError); 58 | 59 | @interface BARemoteJSON : NSObject 60 | 61 | // MUST override to enable communication. 62 | - (NSURLRequest *)remoteJSON:(BARemoteJSON *)remoteJSON requestWithRPCString:(NSString *)RPCString; 63 | 64 | // All method invocations made within the block will be batched. 65 | // Nested invocations of this method execute within the current batch. 66 | - (void)batchCalls:(void (^)())block; 67 | 68 | // Clients call methods defined below to communicate with the backend. 69 | // Completion block can't be nil. 70 | - (void)invokeMethod:(NSString *)methodName completion:(BARemoteJSONCallback)completion; 71 | - (void)invokeMethod:(NSString *)methodName withParameters:(id)parameters completion:(BARemoteJSONCallback)completion; 72 | - (void)notifyMethod:(NSString *)methodName; 73 | - (void)notifyMethod:(NSString *)methodName withParameters:(id)parameters; 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /BADataLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAPersistentCache.h" 31 | 32 | @class BADataLoader; 33 | 34 | 35 | @protocol BADataLoaderDelegate 36 | 37 | - (void)loader:(BADataLoader *)loader didFinishLoadingData:(NSData *)data fromCache:(BOOL)fromCache; 38 | - (void)loader:(BADataLoader *)loader didFailWithError:(NSError *)error; 39 | 40 | @optional 41 | - (void)loaderDidReceiveResponse:(BADataLoader *)loader; 42 | - (void)loaderDidReceiveData:(BADataLoader *)loader; 43 | 44 | @end 45 | 46 | // Quick note on caching 47 | // 48 | // By default loader uses shared persistent cache. 49 | // You can set it to nil to completely disable caching. 50 | // When you ask for data ignoring cache the loader does not check 51 | // if data is in cache but loaded data is saved in the cache. 52 | 53 | @interface BADataLoader : NSObject 54 | 55 | @property(nonatomic, readonly) NSURLRequest *request; 56 | @property(nonatomic, readonly) NSURLResponse *response; 57 | @property(nonatomic, readonly) NSHTTPURLResponse *HTTPResponse; 58 | @property(nonatomic, retain) BAPersistentCache *cache; 59 | @property(nonatomic, readonly) NSUInteger expectedBytesCount; 60 | @property(nonatomic, readonly) NSUInteger receivedBytesCount; 61 | @property(nonatomic, readonly) float progress; // 0..1 62 | @property(nonatomic, assign) id delegate; 63 | @property(nonatomic, readonly) NSMutableDictionary *userInfo; 64 | @property(nonatomic, readonly) NSStringEncoding dataEncoding; 65 | 66 | - (id)initWithRequest:(NSURLRequest *)request; 67 | - (void)startIgnoreCache:(BOOL)ignoreCache; 68 | - (void)cancel; 69 | - (float)progressWithExpectedBytesCount:(NSUInteger)expectedBytesCount; 70 | 71 | + (void)addHTTPQueryToString:(NSMutableString *)query 72 | forDictionary:(NSDictionary *)dict 73 | usingEncoding:(NSStringEncoding)encoding; 74 | 75 | + (void)addHTTPQueryToString:(NSMutableString *)query 76 | forArray:(NSArray *)array 77 | withParameter:(NSString *)parameter 78 | usingEncoding:(NSStringEncoding)encoding; 79 | 80 | + (NSMutableURLRequest *)GETRequestWithURL:(NSURL *)URL; 81 | + (NSMutableURLRequest *)POSTRequestWithURL:(NSURL *)URL data:(NSData *)data; 82 | + (NSMutableURLRequest *)POSTRequestWithURL:(NSURL *)URL form:(NSDictionary *)form; 83 | + (NSMutableURLRequest *)POSTRequestWithURL:(NSURL *)URL JSON:(NSData *)JSONData; 84 | 85 | 86 | // Subclasses API 87 | 88 | - (void)resetConnection; 89 | // If returns YES then received data is cached, otherwise received data is considered invalid and not cached. 90 | - (BOOL)prepareData:(NSData *)data; 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /BAActivityView.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAActivityView.h" 30 | #import 31 | 32 | #define kBAActivityViewPadding 10 33 | 34 | @implementation BAActivityView 35 | 36 | @synthesize indicatorView = _indicatorView; 37 | @synthesize descriptionLabel = _descriptionLabel; 38 | 39 | - (void)dealloc { 40 | [super dealloc]; 41 | [_indicatorView release]; 42 | [_descriptionLabel release]; 43 | } 44 | 45 | - (void)setupView { 46 | self.layer.cornerRadius = 10; 47 | self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7]; 48 | 49 | _indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 50 | [_indicatorView startAnimating]; 51 | [self addSubview:_indicatorView]; 52 | 53 | _descriptionLabel = [[UILabel alloc] init]; 54 | _descriptionLabel.font = [UIFont systemFontOfSize:16]; 55 | _descriptionLabel.textColor = [UIColor whiteColor]; 56 | _descriptionLabel.backgroundColor = [UIColor clearColor]; 57 | _descriptionLabel.textAlignment = UITextAlignmentCenter; 58 | _descriptionLabel.numberOfLines = 10; 59 | _descriptionLabel.lineBreakMode = UILineBreakModeWordWrap; 60 | [self addSubview:_descriptionLabel]; 61 | } 62 | 63 | - (void)awakeFromNib { 64 | [super awakeFromNib]; 65 | [self setupView]; 66 | } 67 | 68 | - (id)initWithFrame:(CGRect)frame { 69 | if ((self = [super initWithFrame:frame])) { 70 | [self setupView]; 71 | } 72 | return self; 73 | } 74 | 75 | - (CGSize)sizeThatFits:(CGSize)size { 76 | const CGFloat width = self.bounds.size.width - kBAActivityViewPadding * 2; 77 | CGSize labelSize = [self.descriptionLabel.text sizeWithFont:self.descriptionLabel.font 78 | constrainedToSize:CGSizeMake(width, CGFLOAT_MAX) 79 | lineBreakMode:self.descriptionLabel.lineBreakMode]; 80 | CGFloat height = self.indicatorView.bounds.size.height + labelSize.height + kBAActivityViewPadding * 3; 81 | return CGSizeMake(size.width, height); 82 | } 83 | 84 | - (void)layoutSubviews { 85 | [super layoutSubviews]; 86 | CGFloat y = kBAActivityViewPadding; 87 | 88 | [self.indicatorView sizeToFit]; 89 | self.indicatorView.center = CGPointMake(self.bounds.size.width / 2, y + self.indicatorView.bounds.size.height / 2); 90 | 91 | y += self.indicatorView.bounds.size.height + kBAActivityViewPadding; 92 | 93 | CGFloat width = self.bounds.size.width - kBAActivityViewPadding * 2; 94 | CGSize labelSize = [self.descriptionLabel.text sizeWithFont:self.descriptionLabel.font 95 | constrainedToSize:CGSizeMake(width, CGFLOAT_MAX) 96 | lineBreakMode:self.descriptionLabel.lineBreakMode]; 97 | self.descriptionLabel.frame = CGRectMake(kBAActivityViewPadding, y, width, labelSize.height); 98 | } 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /NSDate+BADays.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "NSDate+BADays.h" 30 | 31 | @implementation NSDate (BADays) 32 | 33 | - (NSDate *)nextDay { 34 | return [self nextDayInCalendar:[NSCalendar currentCalendar]]; 35 | } 36 | 37 | - (NSDate *)nextDayInCalendar:(NSCalendar *)calendar { 38 | NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease]; 39 | [components setDay:1]; 40 | return [calendar dateByAddingComponents:components toDate:self options:0]; 41 | } 42 | 43 | - (NSDate *)prevDay { 44 | return [self prevDayInCalendar:[NSCalendar currentCalendar]]; 45 | } 46 | 47 | - (NSDate *)prevDayInCalendar:(NSCalendar *)calendar { 48 | NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease]; 49 | [components setDay:-1]; 50 | return [calendar dateByAddingComponents:components toDate:self options:0]; 51 | } 52 | 53 | - (NSDate *)currDay { 54 | return [self currDayInCalendar:[NSCalendar currentCalendar]]; 55 | } 56 | 57 | - (NSDate *)currDayInCalendar:(NSCalendar *)calendar { 58 | const unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; 59 | NSDateComponents *components = [[NSCalendar currentCalendar] components:unitFlags fromDate:self]; 60 | if (!components) { 61 | return self; 62 | } 63 | [components setHour:kBADayHour]; 64 | NSDate *day = [calendar dateFromComponents:components]; 65 | if (!day) { 66 | return self; 67 | } 68 | return day; 69 | } 70 | 71 | - (BOOL)sameDay:(NSDate *)anotherDate { 72 | return [self sameDay:anotherDate inCalendar:[NSCalendar currentCalendar]]; 73 | } 74 | 75 | - (BOOL)sameDay:(NSDate *)anotherDate inCalendar:(NSCalendar *)calendar { 76 | if (!anotherDate) { 77 | return NO; 78 | } 79 | const unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; 80 | NSDateComponents *c1 = [calendar components:unitFlags fromDate:self]; 81 | NSDateComponents *c2 = [calendar components:unitFlags fromDate:anotherDate]; 82 | if (!c1 || !c2) { 83 | return NO; 84 | } 85 | return [c1 year] == [c2 year] && [c1 month] == [c2 month] && [c1 day] == [c2 day]; 86 | } 87 | 88 | - (NSInteger)daysSinceNow { 89 | return [self daysSinceNowInCalendar:[NSCalendar currentCalendar]]; 90 | } 91 | 92 | - (NSInteger)daysSinceNowInCalendar:(NSCalendar *)calendar { 93 | NSDateComponents *components = [calendar components:NSDayCalendarUnit fromDate:[NSDate date] toDate:self options:0]; 94 | return [components day]; 95 | } 96 | 97 | - (NSInteger)currHour { 98 | return [self currHourInCalendar:[NSCalendar currentCalendar]]; 99 | } 100 | 101 | - (NSInteger)currHourInCalendar:(NSCalendar *)calendar { 102 | NSDateComponents *components = [calendar components:NSHourCalendarUnit fromDate:self]; 103 | return [components hour]; 104 | } 105 | 106 | @end 107 | -------------------------------------------------------------------------------- /BAToggleItemLabel.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAToggleItemLabel.h" 31 | 32 | #define kDefaultPadding 10 33 | 34 | @implementation BAToggleItemLabel 35 | 36 | @synthesize selectedBackgroundColor = _selectedBackgroundColor; 37 | @synthesize selectedTextColor = _selectedTextColor; 38 | @synthesize insets = _insets; 39 | @synthesize padding = _padding; 40 | 41 | - (void)dealloc { 42 | [_selectedBackgroundColor release]; 43 | [_selectedTextColor release]; 44 | [_normalTextColor release]; 45 | [super dealloc]; 46 | } 47 | 48 | - (id)initWithFrame:(CGRect)frame { 49 | if ((self = [super initWithFrame:frame])) { 50 | _selectedTextColor = [[UIColor colorWithWhite:0.9 alpha:1.0] retain]; 51 | _selectedBackgroundColor = [[UIColor colorWithWhite:0.0 alpha:0.3] retain]; 52 | self.insets = UIEdgeInsetsMake(kDefaultPadding / 2, kDefaultPadding, kDefaultPadding / 2, kDefaultPadding); 53 | self.padding = kDefaultPadding; 54 | self.textAlignment = UITextAlignmentCenter; 55 | self.backgroundColor = [UIColor clearColor]; 56 | self.opaque = NO; 57 | self.userInteractionEnabled = YES; 58 | } 59 | return self; 60 | } 61 | 62 | - (CGSize)sizeThatFits:(CGSize)size { 63 | size.width -= (self.insets.left + self.insets.right); 64 | size.height -= (self.insets.top + self.insets.bottom); 65 | size = [super sizeThatFits:size]; 66 | size.width += (self.insets.left + self.insets.right); 67 | size.height += (self.insets.top + self.insets.bottom); 68 | return size; 69 | } 70 | 71 | - (void)drawRect:(CGRect)rect { 72 | if (self.selected && self.selectedBackgroundColor) { 73 | CGSize textSize = UIEdgeInsetsInsetRect(self.bounds, self.insets).size; 74 | textSize = [self.text sizeWithFont:self.font 75 | constrainedToSize:textSize 76 | lineBreakMode:self.lineBreakMode]; 77 | [self.selectedBackgroundColor set]; 78 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 79 | CGRect plateRect = CGRectMake((self.bounds.size.width - textSize.width) / 2, 80 | (self.bounds.size.height - textSize.height) / 2, 81 | textSize.width, textSize.height); 82 | plateRect = UIEdgeInsetsInsetRect(plateRect, UIEdgeInsetsMake(-self.padding / 2, -self.padding, 83 | -self.padding / 2, -self.padding)); 84 | UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:plateRect 85 | cornerRadius:(plateRect.size.height / 2)]; 86 | CGContextAddPath(ctx, path.CGPath); 87 | CGContextFillPath(ctx); 88 | } 89 | [super drawRect:self.bounds]; 90 | } 91 | 92 | - (BOOL)selected { 93 | return _selected; 94 | } 95 | 96 | - (void)setSelected:(BOOL)selected { 97 | if (_selected == selected) { 98 | return; 99 | } 100 | _selected = selected; 101 | if (_selected) { 102 | [_normalTextColor release]; 103 | _normalTextColor = [self.textColor retain]; 104 | self.textColor = _selectedTextColor; 105 | } else { 106 | self.textColor = _normalTextColor; 107 | } 108 | [self setNeedsDisplay]; 109 | } 110 | 111 | @end 112 | -------------------------------------------------------------------------------- /BAProgressView.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAProgressView.h" 30 | 31 | @implementation BAProgressView 32 | 33 | - (id)initWithFrame:(CGRect)frame { 34 | if ((self = [super initWithFrame:frame])) { 35 | self.backgroundColor = [UIColor clearColor]; 36 | } 37 | return self; 38 | } 39 | 40 | - (void)dealloc { 41 | [_progressColor release]; 42 | [super dealloc]; 43 | } 44 | 45 | - (float)progress { 46 | return _progress; 47 | } 48 | 49 | - (void)setProgress:(float)progress { 50 | if (_progress == progress) { 51 | return; 52 | } 53 | if (progress < 0) { 54 | progress = 0; 55 | } else if (progress > 1) { 56 | progress = 1; 57 | } 58 | _progress = progress; 59 | [self setNeedsDisplay]; 60 | } 61 | 62 | - (BOOL)failed { 63 | return _failed; 64 | } 65 | 66 | - (void)setFailed:(BOOL)failed { 67 | if (_failed == failed) { 68 | return; 69 | } 70 | _failed = failed; 71 | [self setNeedsDisplay]; 72 | } 73 | 74 | - (UIColor *)progressColor { 75 | return _progressColor; 76 | } 77 | 78 | - (void)setProgressColor:(UIColor *)progressColor { 79 | if (_progressColor == progressColor) { 80 | return; 81 | } 82 | [_progressColor release]; 83 | _progressColor = [progressColor retain]; 84 | [self setNeedsDisplay]; 85 | } 86 | 87 | - (void)drawRect:(CGRect)rect { 88 | const CGFloat lw = 3; 89 | const CGFloat ps = MIN(self.bounds.size.width / 2, self.bounds.size.height / 2) - lw; 90 | const CGPoint cp = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2); 91 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 92 | 93 | if (self.failed) { 94 | 95 | // progress plate 96 | CGContextBeginPath(ctx); 97 | CGContextAddArc(ctx, cp.x, cp.y, ps, 0, M_PI * 2, 0); 98 | CGContextClosePath(ctx); 99 | [self.progressColor set]; 100 | CGContextFillPath(ctx); 101 | 102 | // cross 103 | CGContextBeginPath(ctx); 104 | CGFloat cd = ps * 0.35; 105 | CGContextMoveToPoint(ctx, cp.x + cd, cp.y + cd); 106 | CGContextAddLineToPoint(ctx, cp.x - cd, cp.y - cd); 107 | CGContextMoveToPoint(ctx, cp.x - cd, cp.y + cd); 108 | CGContextAddLineToPoint(ctx, cp.x + cd, cp.y - cd); 109 | CGContextMoveToPoint(ctx, cp.x + cd, cp.y + cd); 110 | CGContextClosePath(ctx); 111 | CGContextSetLineWidth(ctx, 4); 112 | CGContextSetLineCap(ctx, kCGLineCapRound); 113 | [self.backgroundColor set]; 114 | CGContextStrokePath(ctx); 115 | 116 | } else { 117 | 118 | // progress pie 119 | if (self.progress > 0) { 120 | CGContextBeginPath(ctx); 121 | CGContextMoveToPoint(ctx, cp.x, cp.y); 122 | CGContextAddArc(ctx, cp.x, cp.y, ps - lw - 1, -M_PI_2, -M_PI_2 + M_PI * 2 * self.progress, 0); 123 | CGContextClosePath(ctx); 124 | [self.progressColor set]; 125 | CGContextFillPath(ctx); 126 | } 127 | 128 | // progress border 129 | CGContextBeginPath(ctx); 130 | CGContextAddArc(ctx, cp.x, cp.y, ps, 0, M_PI * 2, 0); 131 | CGContextClosePath(ctx); 132 | [self.progressColor set]; 133 | CGContextSetLineWidth(ctx, lw); 134 | CGContextStrokePath(ctx); 135 | 136 | } 137 | } 138 | 139 | @end 140 | -------------------------------------------------------------------------------- /BARemoteImageToggleItem.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BARemoteImageToggleItem.h" 31 | 32 | @implementation BARemoteImageToggleItem 33 | 34 | @synthesize imageView = _imageView; 35 | @synthesize imageInsets = _imageInsets; 36 | @synthesize selectedOutlineColor = _selectedOutlineColor; 37 | 38 | - (void)dealloc { 39 | [_imageView release]; 40 | [_selectedOutlineColor release]; 41 | [super dealloc]; 42 | } 43 | 44 | - (id)init { 45 | if ((self = [super init])) { 46 | _imageView = [[BARemoteImageView alloc] init]; 47 | [self addSubview:_imageView]; 48 | } 49 | return self; 50 | } 51 | 52 | - (CGSize)sizeThatFits:(CGSize)size { 53 | CGSize viewSize = { 0, 0 }; 54 | if (self.imageView.image) { 55 | viewSize = self.imageView.image.size; 56 | } 57 | CGSize maxViewSize = CGSizeMake(size.width - (self.imageInsets.left + self.imageInsets.right), 58 | size.height - (self.imageInsets.top + self.imageInsets.bottom)); 59 | if (maxViewSize.width < viewSize.width && viewSize.width > 0 && maxViewSize.width > 0) { 60 | double scale = maxViewSize.width / viewSize.width; 61 | viewSize.width = roundf(maxViewSize.width); 62 | viewSize.height = roundf(scale * viewSize.height); 63 | } 64 | if (maxViewSize.height < viewSize.height && viewSize.height > 0 && maxViewSize.height > 0) { 65 | double scale = maxViewSize.height / viewSize.height; 66 | viewSize.width = roundf(scale * viewSize.width); 67 | viewSize.height = roundf(maxViewSize.height); 68 | } 69 | return CGSizeMake(viewSize.width + (self.imageInsets.left + self.imageInsets.right), 70 | viewSize.height + (self.imageInsets.top + self.imageInsets.bottom)); 71 | } 72 | 73 | - (void)layoutSubviews { 74 | [super layoutSubviews]; 75 | CGRect r = UIEdgeInsetsInsetRect(self.bounds, self.imageInsets); 76 | if (self.imageView.image) { 77 | CGSize size = self.imageView.image.size; 78 | if (r.size.width < size.width && size.width > 0 && r.size.width > 0) { 79 | double scale = r.size.width / size.width; 80 | size.width = roundf(r.size.width); 81 | size.height = roundf(scale * size.height); 82 | } 83 | if (r.size.height < size.height && size.height > 0 && r.size.height > 0) { 84 | double scale = r.size.height / size.height; 85 | size.width = roundf(scale * size.width); 86 | size.height = roundf(r.size.height); 87 | } 88 | self.imageView.frame = CGRectMake(roundf(r.origin.x + (r.size.width - size.width) / 2), 89 | roundf(r.origin.y + (r.size.height - size.height) / 2), 90 | size.width, size.height); 91 | } else { 92 | self.imageView.frame = r; 93 | } 94 | } 95 | 96 | - (void)drawRect:(CGRect)rect { 97 | if (self.selected) { 98 | if (self.selectedOutlineColor) { 99 | [self.selectedOutlineColor set]; 100 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 101 | CGContextSetLineWidth(ctx, 1); 102 | CGRect r = self.imageView.frame; 103 | r = CGRectInset(r, -1, -1); 104 | UIRectFrame(r); 105 | } 106 | } 107 | } 108 | 109 | - (BOOL)selected { 110 | return _selected; 111 | } 112 | 113 | - (void)setSelected:(BOOL)selected { 114 | if (_selected == selected) { 115 | return; 116 | } 117 | _selected = selected; 118 | [self setNeedsDisplay]; 119 | } 120 | 121 | @end 122 | -------------------------------------------------------------------------------- /BAGradientView.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import 30 | #import "BAGradientView.h" 31 | 32 | @interface BAGradientView (Private) 33 | 34 | @property(nonatomic, readonly) CAGradientLayer *gradientLayer; 35 | 36 | - (void)updateGradientDirection; 37 | - (void)updateGradientColors; 38 | 39 | @end 40 | 41 | 42 | @implementation BAGradientView 43 | 44 | - (void)dealloc { 45 | [super dealloc]; 46 | } 47 | 48 | - (void)setupView { 49 | _gradientDirection = BAGradientViewDirectionDown; 50 | [self updateGradientDirection]; 51 | _startColor = [[UIColor clearColor] retain]; 52 | _endColor = [[UIColor blackColor] retain]; 53 | [self updateGradientColors]; 54 | } 55 | 56 | - (void)awakeFromNib { 57 | [self setupView]; 58 | [super awakeFromNib]; 59 | } 60 | 61 | - (id)initWithFrame:(CGRect)frame { 62 | if ((self = [super initWithFrame:frame])) { 63 | self.backgroundColor = [UIColor clearColor]; 64 | self.opaque = NO; 65 | [self setupView]; 66 | } 67 | return self; 68 | } 69 | 70 | - (UIColor *)startColor { 71 | return _startColor; 72 | } 73 | 74 | - (void)setStartColor:(UIColor *)color { 75 | if (_startColor == color) { 76 | return; 77 | } 78 | [_startColor release]; 79 | _startColor = [color retain]; 80 | [self updateGradientColors]; 81 | } 82 | 83 | - (UIColor *)endColor { 84 | return _endColor; 85 | } 86 | 87 | - (void)setEndColor:(UIColor *)color { 88 | if (_endColor == color) { 89 | return; 90 | } 91 | [_endColor release]; 92 | _endColor = [color retain]; 93 | [self updateGradientColors]; 94 | } 95 | 96 | - (void)updateGradientColors { 97 | UIColor *startColor = self.startColor; 98 | if (!startColor) { 99 | startColor = [UIColor clearColor]; 100 | } 101 | UIColor *endColor = self.endColor; 102 | if (!endColor) { 103 | endColor = [UIColor clearColor]; 104 | } 105 | self.gradientLayer.colors = [NSArray arrayWithObjects:(id)startColor.CGColor, (id)endColor.CGColor, nil]; 106 | } 107 | 108 | - (BAGradientViewDirection)gradientDirection { 109 | return _gradientDirection; 110 | } 111 | 112 | - (void)setGradientDirection:(BAGradientViewDirection)gradientDirection { 113 | if (_gradientDirection != gradientDirection) { 114 | _gradientDirection = gradientDirection; 115 | [self updateGradientDirection]; 116 | } 117 | } 118 | 119 | - (void)updateGradientDirection { 120 | switch (self.gradientDirection) { 121 | case BAGradientViewDirectionDown: { 122 | self.gradientLayer.startPoint = CGPointMake(0.5, 0); 123 | self.gradientLayer.endPoint = CGPointMake(0.5, 1); 124 | break; 125 | } 126 | case BAGradientViewDirectionUp: { 127 | self.gradientLayer.startPoint = CGPointMake(0.5, 1); 128 | self.gradientLayer.endPoint = CGPointMake(0.5, 0); 129 | break; 130 | } 131 | case BAGradientViewDirectionRight: { 132 | self.gradientLayer.startPoint = CGPointMake(0, 0.5); 133 | self.gradientLayer.endPoint = CGPointMake(1, 0.5); 134 | break; 135 | } 136 | case BAGradientViewDirectionLeft: { 137 | self.gradientLayer.startPoint = CGPointMake(1, 0.5); 138 | self.gradientLayer.endPoint = CGPointMake(0, 0.5); 139 | break; 140 | } 141 | } 142 | } 143 | 144 | + (Class)layerClass { 145 | return [CAGradientLayer class]; 146 | } 147 | 148 | - (CAGradientLayer *)gradientLayer { 149 | return (CAGradientLayer *)self.layer; 150 | } 151 | 152 | @end 153 | -------------------------------------------------------------------------------- /BAJSONLoader.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAJSONLoader.h" 30 | #import "BARuntime.h" 31 | 32 | @implementation BAJSONLoader 33 | 34 | @synthesize JSONValue = _JSONValue; 35 | 36 | - (void)resetConnection { 37 | [super resetConnection]; 38 | [_JSONValue release]; 39 | _JSONValue = nil; 40 | } 41 | 42 | - (BOOL)prepareData:(NSData *)data { 43 | if (_JSONValue) { 44 | [_JSONValue release]; 45 | _JSONValue = nil; 46 | } 47 | 48 | // NSString *text = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; 49 | // NSLog(@"%@", [self.request URL]); 50 | // NSLog(@"%@", text); 51 | 52 | NSError *error = nil; 53 | _JSONValue = [[[self class] parseJSONData:data error:&error] retain]; 54 | if (error) { 55 | NSLog(@"Error parsing JSON from %@: %@", [self.request URL], error); 56 | } 57 | return !error; 58 | } 59 | 60 | + (id)parseJSONData:(NSData *)data error:(NSError **)error { 61 | return [BARuntime parseJSONData:data error:error]; 62 | } 63 | 64 | + (NSString *)stringFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key { 65 | id value = [JSONValue objectForKey:key]; 66 | if (value && [value isKindOfClass:[NSString class]]) { 67 | return value; 68 | } 69 | return nil; 70 | } 71 | 72 | + (NSArray *)arrayFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key { 73 | id value = [JSONValue objectForKey:key]; 74 | if (value && [value isKindOfClass:[NSArray class]]) { 75 | return value; 76 | } 77 | return nil; 78 | } 79 | 80 | + (NSDictionary *)dictionaryFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key { 81 | id value = [JSONValue objectForKey:key]; 82 | if (value && [value isKindOfClass:[NSDictionary class]]) { 83 | return value; 84 | } 85 | return nil; 86 | } 87 | 88 | + (BOOL)boolFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key { 89 | return [self boolFromJSONValue:JSONValue forKey:key defaultValue:NO]; 90 | } 91 | 92 | + (BOOL)boolFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key defaultValue:(BOOL)defaultValue { 93 | id value = [JSONValue objectForKey:key]; 94 | if (value && [value isKindOfClass:[NSString class]]) { 95 | return [value boolValue]; 96 | } else if (value && [value isKindOfClass:[NSNumber class]]) { 97 | return [value boolValue]; 98 | } 99 | return defaultValue; 100 | } 101 | 102 | + (int)intFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key { 103 | return [self intFromJSONValue:JSONValue forKey:key defaultValue:0]; 104 | } 105 | 106 | + (int)intFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key defaultValue:(int)defaultValue { 107 | id value = [JSONValue objectForKey:key]; 108 | if (value && [value isKindOfClass:[NSString class]]) { 109 | return [value intValue]; 110 | } else if (value && [value isKindOfClass:[NSNumber class]]) { 111 | return [value intValue]; 112 | } 113 | return defaultValue; 114 | } 115 | 116 | + (double)doubleFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key { 117 | return [self doubleFromJSONValue:JSONValue forKey:key defaultValue:0]; 118 | } 119 | 120 | + (double)doubleFromJSONValue:(NSDictionary *)JSONValue forKey:(NSString *)key defaultValue:(int)defaultValue { 121 | id value = [JSONValue objectForKey:key]; 122 | if (value && [value isKindOfClass:[NSString class]]) { 123 | return [value doubleValue]; 124 | } else if (value && [value isKindOfClass:[NSNumber class]]) { 125 | return [value doubleValue]; 126 | } 127 | return defaultValue; 128 | } 129 | 130 | @end 131 | -------------------------------------------------------------------------------- /BAScrollViewProxyDelegate.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAScrollViewProxyDelegate.h" 30 | 31 | @implementation BAScrollViewProxyDelegate 32 | 33 | @synthesize delegate = _delegate; 34 | 35 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 36 | if ([self.delegate respondsToSelector:@selector(scrollViewDidScroll:)]) { 37 | [self.delegate scrollViewDidScroll:scrollView]; 38 | } 39 | } 40 | 41 | - (void)scrollViewDidZoom:(UIScrollView *)scrollView { 42 | if ([self.delegate respondsToSelector:@selector(scrollViewDidZoom:)]) { 43 | [self.delegate scrollViewDidZoom:scrollView]; 44 | } 45 | } 46 | 47 | - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { 48 | if ([self.delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)]) { 49 | [self.delegate scrollViewWillBeginDragging:scrollView]; 50 | } 51 | } 52 | 53 | - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { 54 | if ([self.delegate respondsToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)]) { 55 | [self.delegate scrollViewWillEndDragging:scrollView withVelocity:velocity targetContentOffset:targetContentOffset]; 56 | } 57 | } 58 | 59 | - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { 60 | if ([self.delegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)]) { 61 | [self.delegate scrollViewDidEndDragging:scrollView willDecelerate:decelerate]; 62 | } 63 | } 64 | 65 | - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView { 66 | if ([self.delegate respondsToSelector:@selector(scrollViewWillBeginDecelerating:)]) { 67 | [self.delegate scrollViewWillBeginDecelerating:scrollView]; 68 | } 69 | } 70 | 71 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { 72 | if ([self.delegate respondsToSelector:@selector(scrollViewDidEndDecelerating:)]) { 73 | [self.delegate scrollViewDidEndDecelerating:scrollView]; 74 | } 75 | } 76 | 77 | - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView { 78 | if ([self.delegate respondsToSelector:@selector(scrollViewDidEndScrollingAnimation:)]) { 79 | [self.delegate scrollViewDidEndScrollingAnimation:scrollView]; 80 | } 81 | } 82 | 83 | - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { 84 | if ([self.delegate respondsToSelector:@selector(viewForZoomingInScrollView:)]) { 85 | [self.delegate viewForZoomingInScrollView:scrollView]; 86 | } 87 | return nil; 88 | } 89 | 90 | - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view { 91 | if ([self.delegate respondsToSelector:@selector(scrollViewWillBeginZooming:withView:)]) { 92 | [self.delegate scrollViewWillBeginZooming:scrollView withView:view]; 93 | } 94 | } 95 | 96 | - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale { 97 | if ([self.delegate respondsToSelector:@selector(scrollViewDidEndZooming:withView:atScale:)]) { 98 | [self.delegate scrollViewDidEndZooming:scrollView withView:view atScale:scale]; 99 | } 100 | } 101 | 102 | - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView { 103 | if ([self.delegate respondsToSelector:@selector(scrollViewShouldScrollToTop:)]) { 104 | return [self.delegate scrollViewShouldScrollToTop:scrollView]; 105 | } 106 | return YES; 107 | } 108 | 109 | - (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView { 110 | if ([self.delegate respondsToSelector:@selector(scrollViewDidScrollToTop:)]) { 111 | [self.delegate scrollViewDidScrollToTop:scrollView]; 112 | } 113 | } 114 | 115 | @end 116 | -------------------------------------------------------------------------------- /BAProgressLayer.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BAProgressLayer.h" 30 | 31 | @implementation BAProgressLayer { 32 | @private 33 | float _progress; 34 | BOOL _failed; 35 | CGColorRef _progressColor; 36 | } 37 | 38 | - (void)dealloc { 39 | CGColorRelease(_progressColor); 40 | [super dealloc]; 41 | } 42 | 43 | - (id)initWithLayer:(id)layer { 44 | if ((self = [super initWithLayer:layer])) { 45 | BAProgressLayer *sourceLayer = (BAProgressLayer *)layer; 46 | self.progress = sourceLayer.progress; 47 | self.failed = sourceLayer.failed; 48 | self.progressColor = sourceLayer.progressColor; 49 | } 50 | return self; 51 | } 52 | 53 | + (BOOL)needsDisplayForKey:(NSString *)key { 54 | if ([key isEqualToString:@"progress"] || 55 | [key isEqualToString:@"failed"] || 56 | [key isEqualToString:@"progressColor"]) 57 | { 58 | return YES; 59 | } else { 60 | return [super needsDisplayForKey:key]; 61 | } 62 | } 63 | 64 | - (float)progress { 65 | return _progress; 66 | } 67 | 68 | - (void)setProgress:(float)progress { 69 | if (_progress == progress) { 70 | return; 71 | } 72 | if (progress < 0) { 73 | progress = 0; 74 | } else if (progress > 1) { 75 | progress = 1; 76 | } 77 | _progress = progress; 78 | [self setNeedsDisplay]; 79 | } 80 | 81 | - (BOOL)failed { 82 | return _failed; 83 | } 84 | 85 | - (void)setFailed:(BOOL)failed { 86 | if (_failed == failed) { 87 | return; 88 | } 89 | _failed = failed; 90 | [self setNeedsDisplay]; 91 | } 92 | 93 | - (CGColorRef)progressColor { 94 | return _progressColor; 95 | } 96 | 97 | - (void)setProgressColor:(CGColorRef)progressColor { 98 | if (_progressColor == progressColor) { 99 | return; 100 | } 101 | CGColorRelease(_progressColor); 102 | _progressColor = progressColor; 103 | CGColorRetain(_progressColor); 104 | [self setNeedsDisplay]; 105 | } 106 | 107 | - (void)drawInContext:(CGContextRef)ctx { 108 | const CGFloat lw = 3; 109 | const CGFloat ps = MIN(self.bounds.size.width / 2, self.bounds.size.height / 2) - lw; 110 | const CGPoint cp = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2); 111 | 112 | if (self.failed) { 113 | 114 | // progress plate 115 | CGContextBeginPath(ctx); 116 | CGContextAddArc(ctx, cp.x, cp.y, ps, 0, M_PI * 2, 0); 117 | CGContextClosePath(ctx); 118 | CGContextSetFillColorWithColor(ctx, self.progressColor); 119 | CGContextFillPath(ctx); 120 | 121 | // cross 122 | CGContextBeginPath(ctx); 123 | CGFloat cd = ps * 0.35; 124 | CGContextMoveToPoint(ctx, cp.x + cd, cp.y + cd); 125 | CGContextAddLineToPoint(ctx, cp.x - cd, cp.y - cd); 126 | CGContextMoveToPoint(ctx, cp.x - cd, cp.y + cd); 127 | CGContextAddLineToPoint(ctx, cp.x + cd, cp.y - cd); 128 | CGContextMoveToPoint(ctx, cp.x + cd, cp.y + cd); 129 | CGContextClosePath(ctx); 130 | CGContextSetLineWidth(ctx, 4); 131 | CGContextSetLineCap(ctx, kCGLineCapRound); 132 | CGContextSetStrokeColorWithColor(ctx, self.backgroundColor); 133 | CGContextStrokePath(ctx); 134 | 135 | } else { 136 | 137 | // progress pie 138 | if (self.progress > 0) { 139 | CGContextBeginPath(ctx); 140 | CGContextMoveToPoint(ctx, cp.x, cp.y); 141 | CGContextAddArc(ctx, cp.x, cp.y, ps - lw - 1, -M_PI_2, -M_PI_2 + M_PI * 2 * self.progress, 0); 142 | CGContextClosePath(ctx); 143 | CGContextSetFillColorWithColor(ctx, self.progressColor); 144 | CGContextFillPath(ctx); 145 | } 146 | 147 | // progress border 148 | CGContextBeginPath(ctx); 149 | CGContextAddArc(ctx, cp.x, cp.y, ps, 0, M_PI * 2, 0); 150 | CGContextClosePath(ctx); 151 | CGContextSetStrokeColorWithColor(ctx, self.progressColor); 152 | CGContextSetLineWidth(ctx, lw); 153 | CGContextStrokePath(ctx); 154 | 155 | } 156 | } 157 | 158 | @end 159 | -------------------------------------------------------------------------------- /BARemoteImageView.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BARemoteImageView.h" 30 | 31 | @implementation BARemoteImageView { 32 | @private 33 | NSURL *_remoteImageURL; 34 | BAImageLoader *_loader; 35 | } 36 | 37 | @synthesize animateImageUpdate = _animateImageUpdate; 38 | @synthesize delegate = _delegate; 39 | 40 | - (void)resetLoader { 41 | if (_loader) { 42 | _loader.delegate = nil; // IMPORTANT: nullify delegate since loader is retained by connection and can outlive us 43 | [_loader release]; 44 | _loader = nil; 45 | } 46 | } 47 | 48 | - (void)dealloc { 49 | [self resetLoader]; 50 | [_remoteImageURL release]; 51 | [super dealloc]; 52 | } 53 | 54 | - (UIImageView *)duplicate { 55 | UIImageView *imageView = [[[UIImageView alloc] initWithImage:self.image] autorelease]; 56 | imageView.frame = self.bounds; 57 | imageView.contentMode = self.contentMode; 58 | imageView.clipsToBounds = self.clipsToBounds; 59 | return imageView; 60 | } 61 | 62 | - (void)updateRemoteImage:(UIImage *)remoteImage animated:(BOOL)animated { 63 | UIImageView *coverImageView = nil; 64 | if (animated && self.animateImageUpdate) { 65 | coverImageView = [self duplicate]; 66 | [self insertSubview:coverImageView atIndex:0]; 67 | } 68 | self.image = remoteImage; 69 | if (coverImageView) { 70 | [UIView animateWithDuration:0.3 71 | animations:^{ 72 | coverImageView.alpha = 0; 73 | } completion:^(BOOL finished) { 74 | [coverImageView removeFromSuperview]; 75 | }]; 76 | } 77 | } 78 | 79 | - (NSURL *)remoteImageURL { 80 | return _remoteImageURL; 81 | } 82 | 83 | - (void)setRemoteImageURL:(NSURL *)remoteImageURL { 84 | if (_remoteImageURL == remoteImageURL) { 85 | return; 86 | } 87 | [_remoteImageURL release]; 88 | _remoteImageURL = [remoteImageURL retain]; 89 | 90 | [self resetLoader]; 91 | if (_remoteImageURL) { 92 | // Check cache first so update is immediate; loader defers update 93 | UIImage *image = [[BAPersistentCache persistentCache] imageForKey:[_remoteImageURL absoluteString]]; 94 | if (image) { 95 | [self updateRemoteImage:image animated:NO]; 96 | } else { 97 | NSURLRequest *request = [BADataLoader GETRequestWithURL:_remoteImageURL]; 98 | _loader = [[BAImageLoader alloc] initWithRequest:request]; 99 | _loader.delegate = self; 100 | [_loader startIgnoreCache:NO]; 101 | } 102 | } 103 | } 104 | 105 | - (void)loader:(BADataLoader *)loader didFinishLoadingData:(NSData *)data fromCache:(BOOL)fromCache { 106 | UIImage *image = ((BAImageLoader *)loader).image; 107 | if (image) { 108 | [self updateRemoteImage:image animated:!fromCache]; 109 | } 110 | [self resetLoader]; 111 | if (self.delegate && [self.delegate respondsToSelector:@selector(remoteImageViewDidLoad:)]) { 112 | [self.delegate remoteImageViewDidLoad:self]; 113 | } 114 | } 115 | 116 | - (void)loader:(BADataLoader *)loader didFailWithError:(NSError *)error { 117 | [self resetLoader]; 118 | if (self.delegate && [self.delegate respondsToSelector:@selector(remoteImageView:didFailWithError:)]) { 119 | [self.delegate remoteImageView:self didFailWithError:error]; 120 | } 121 | } 122 | 123 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 124 | if (self.delegate && [self.delegate respondsToSelector:@selector(remoteImageView:touchesBegan:withEvent:)]) { 125 | [self.delegate remoteImageView:self touchesBegan:touches withEvent:event]; 126 | } 127 | [super touchesBegan:touches withEvent:event]; 128 | } 129 | 130 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 131 | if (self.delegate && [self.delegate respondsToSelector:@selector(remoteImageView:touchesEnded:withEvent:)]) { 132 | [self.delegate remoteImageView:self touchesEnded:touches withEvent:event]; 133 | } 134 | [super touchesEnded:touches withEvent:event]; 135 | } 136 | 137 | - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { 138 | if (self.delegate && [self.delegate respondsToSelector:@selector(remoteImageView:touchesCancelled:withEvent:)]) { 139 | [self.delegate remoteImageView:self touchesCancelled:touches withEvent:event]; 140 | } 141 | [super touchesCancelled:touches withEvent:event]; 142 | } 143 | 144 | @end 145 | -------------------------------------------------------------------------------- /BARuntime.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BARuntime.h" 30 | #import 31 | 32 | @implementation BARuntime 33 | 34 | + (id)parseJSONData:(NSData *)data error:(NSError **)error { 35 | if (!data || [data length] == 0) { 36 | return nil; 37 | } 38 | 39 | if ([data respondsToSelector:NSSelectorFromString(@"objectFromJSONData")]) { 40 | id JSONValue = nil; 41 | @try { 42 | JSONValue = [data performSelector:NSSelectorFromString(@"objectFromJSONData")]; 43 | } 44 | @catch (NSException *e) { 45 | if (error) { 46 | *error = [NSError errorWithDomain:@"BaseAppKit" 47 | code:0 48 | userInfo:[NSDictionary dictionaryWithObject:e.reason 49 | forKey:NSLocalizedDescriptionKey]]; 50 | } 51 | } 52 | return JSONValue; 53 | } 54 | 55 | Class serClass = NSClassFromString(@"NSJSONSerialization"); 56 | if (serClass) { 57 | id JSONValue = nil; 58 | @try { 59 | return objc_msgSend(serClass, @selector(JSONObjectWithData:options:error:), 60 | data, [NSNumber numberWithInt:NSJSONReadingAllowFragments], error); 61 | } 62 | @catch (NSException *e) { 63 | if (error) { 64 | *error = [NSError errorWithDomain:@"BaseAppKit" 65 | code:0 66 | userInfo:[NSDictionary dictionaryWithObject:e.reason 67 | forKey:NSLocalizedDescriptionKey]]; 68 | } 69 | } 70 | return JSONValue; 71 | } 72 | 73 | NSLog(@"JSON parser is not available"); 74 | return nil; 75 | } 76 | 77 | + (NSData *)serializeJSONToData:(id)JSONValue error:(NSError **)error { 78 | if (!JSONValue) { 79 | return nil; 80 | } 81 | 82 | if ([JSONValue respondsToSelector:@selector(JSONDataWithOptions:error:)]) { 83 | NSData *data = nil; 84 | @try { 85 | data = [JSONValue performSelector:@selector(JSONDataWithOptions:error:) 86 | withObject:[NSNumber numberWithInt:0] 87 | withObject:(id)error]; 88 | } 89 | @catch (NSException *e) { 90 | if (error) { 91 | *error = [NSError errorWithDomain:@"BaseAppKit" 92 | code:0 93 | userInfo:[NSDictionary dictionaryWithObject:e.reason 94 | forKey:NSLocalizedDescriptionKey]]; 95 | } 96 | } 97 | return data; 98 | } 99 | 100 | Class serClass = NSClassFromString(@"NSJSONSerialization"); 101 | if (serClass) { 102 | NSData *data = nil; 103 | @try { 104 | data = objc_msgSend(serClass, @selector(dataWithJSONObject:options:error:), 105 | JSONValue, 0, error); 106 | } 107 | @catch (NSException *e) { 108 | if (error) { 109 | *error = [NSError errorWithDomain:@"BaseAppKit" 110 | code:0 111 | userInfo:[NSDictionary dictionaryWithObject:e.reason 112 | forKey:NSLocalizedDescriptionKey]]; 113 | } 114 | } 115 | return data; 116 | } 117 | 118 | NSLog(@"JSON parser is not available"); 119 | return nil; 120 | } 121 | 122 | + (NSString *)serializeJSONToString:(id)JSONValue error:(NSError **)error { 123 | return [self serializeJSONToString:JSONValue formatted:NO error:error]; 124 | } 125 | 126 | + (NSString *)serializeJSONToString:(id)JSONValue formatted:(BOOL)formatted error:(NSError **)error { 127 | if (!JSONValue) { 128 | return nil; 129 | } 130 | 131 | if ([JSONValue respondsToSelector:@selector(JSONStringWithOptions:error:)]) { 132 | NSString *data = nil; 133 | @try { 134 | data = [JSONValue performSelector:@selector(JSONStringWithOptions:error:) 135 | withObject:[NSNumber numberWithInt:(formatted ? 1 /*JKSerializeOptionPretty*/ : 0)] 136 | withObject:(id)error]; 137 | } 138 | @catch (NSException *e) { 139 | if (error) { 140 | *error = [NSError errorWithDomain:@"BaseAppKit" 141 | code:0 142 | userInfo:[NSDictionary dictionaryWithObject:e.reason 143 | forKey:NSLocalizedDescriptionKey]]; 144 | } 145 | } 146 | return data; 147 | } 148 | 149 | Class serClass = NSClassFromString(@"NSJSONSerialization"); 150 | if (serClass) { 151 | NSData *data = nil; 152 | @try { 153 | data = objc_msgSend(serClass, @selector(dataWithJSONObject:options:error:), 154 | JSONValue, (formatted ? NSJSONWritingPrettyPrinted : 0), error); 155 | } 156 | @catch (NSException *e) { 157 | if (error) { 158 | *error = [NSError errorWithDomain:@"BaseAppKit" 159 | code:0 160 | userInfo:[NSDictionary dictionaryWithObject:e.reason 161 | forKey:NSLocalizedDescriptionKey]]; 162 | } 163 | } 164 | if (!data) { 165 | return nil; 166 | } 167 | return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; 168 | } 169 | 170 | NSLog(@"JSON parser is not available"); 171 | return nil; 172 | } 173 | 174 | @end 175 | -------------------------------------------------------------------------------- /BALabel.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011 Dmitry Stadnik. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY DMITRY STADNIK ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DMITRY STADNIK OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Dmitry Stadnik. 27 | */ 28 | 29 | #import "BALabel.h" 30 | 31 | CGPathRef CGPathCreateRoundBezel(CGRect bounds, CGFloat lineWidth); 32 | 33 | CGPathRef CGPathCreateRoundBezel(CGRect bounds, CGFloat lineWidth) { 34 | CGRect b = CGRectInset(bounds, lineWidth, lineWidth); 35 | const CGFloat w = b.size.width; 36 | const CGFloat h = b.size.height; 37 | if (w <= h) { 38 | UIBezierPath *bpath = [UIBezierPath bezierPathWithOvalInRect:b]; 39 | CGPathRef path = bpath.CGPath; 40 | CGPathRetain(path); 41 | return path; 42 | } 43 | const CGFloat x = b.origin.x; 44 | const CGFloat y = b.origin.y; 45 | CGMutablePathRef path = CGPathCreateMutable(); 46 | const CGFloat r = h / 2; 47 | CGPathMoveToPoint(path, NULL, x + r, y); 48 | CGPathAddLineToPoint(path, NULL, x + w - r, y); 49 | CGPathAddArc(path, NULL, x + w - r, y + r, r, -M_PI_2, M_PI_2, NO); 50 | CGPathAddLineToPoint(path, NULL, x + r, y + h); 51 | CGPathAddArc(path, NULL, x + r, y + r, r, M_PI_2, -M_PI_2, NO); 52 | return path; 53 | } 54 | 55 | @implementation BALabel { 56 | @private 57 | UIEdgeInsets _textInsets; 58 | BAVerticalAlignment _verticalAlignment; 59 | BALabelBezel _bezel; 60 | CGFloat _bezelLineWidth; 61 | UIColor *_bezelColor; 62 | 63 | CGFloat _fitMaxWidth; 64 | CGFloat _fitMaxHeight; 65 | int _fit; 66 | } 67 | 68 | - (void)dealloc { 69 | [_bezelColor release]; 70 | [super dealloc]; 71 | } 72 | 73 | - (UIEdgeInsets)textInsets { 74 | return _textInsets; 75 | } 76 | 77 | - (void)setTextInsets:(UIEdgeInsets)textInsets { 78 | if (UIEdgeInsetsEqualToEdgeInsets(_textInsets, textInsets)) { 79 | return; 80 | } 81 | _textInsets = textInsets; 82 | [self setNeedsDisplay]; 83 | } 84 | 85 | - (BAVerticalAlignment)verticalAlignment { 86 | return _verticalAlignment; 87 | } 88 | 89 | - (void)setVerticalAlignment:(BAVerticalAlignment)verticalAlignment { 90 | if (_verticalAlignment == verticalAlignment) { 91 | return; 92 | } 93 | _verticalAlignment = verticalAlignment; 94 | [self setNeedsDisplay]; 95 | } 96 | 97 | - (BALabelBezel)bezel { 98 | return _bezel; 99 | } 100 | 101 | - (void)setBezel:(BALabelBezel)bezel { 102 | if (_bezel == bezel) { 103 | return; 104 | } 105 | _bezel = bezel; 106 | [self setNeedsDisplay]; 107 | } 108 | 109 | - (CGFloat)bezelLineWidth { 110 | return _bezelLineWidth; 111 | } 112 | 113 | - (void)setBezelLineWidth:(CGFloat)bezelLineWidth { 114 | if (_bezelLineWidth == bezelLineWidth) { 115 | return; 116 | } 117 | _bezelLineWidth = bezelLineWidth; 118 | [self setNeedsDisplay]; 119 | } 120 | 121 | - (UIColor *)bezelColor { 122 | return _bezelColor; 123 | } 124 | 125 | - (void)setBezelColor:(UIColor *)bezelColor { 126 | if (_bezelColor == bezelColor) { 127 | return; 128 | } 129 | [_bezelColor release]; 130 | _bezelColor = [bezelColor retain]; 131 | [self setNeedsDisplay]; 132 | } 133 | 134 | - (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines { 135 | CGRect r = bounds; 136 | if (_fit > 0) { 137 | r.size.width = _fitMaxWidth; 138 | r.size.height = _fitMaxHeight; 139 | } 140 | const CGFloat wd = self.textInsets.left + self.textInsets.right; 141 | const CGFloat hd = self.textInsets.top + self.textInsets.bottom; 142 | r.size.width -= wd; 143 | r.size.height -= hd; 144 | r = [super textRectForBounds:r limitedToNumberOfLines:numberOfLines]; 145 | r.size.width += wd; 146 | r.size.height += hd; 147 | return r; 148 | } 149 | 150 | - (void)drawTextInRect:(CGRect)rect { 151 | CGRect tr = [self textRectForBounds:self.bounds limitedToNumberOfLines:self.numberOfLines]; 152 | const CGFloat hd = self.bounds.size.height - tr.size.height; 153 | if (self.verticalAlignment == BAVerticalAlignmentCenter) { 154 | tr.origin.y += rint(hd / 2); 155 | } else if (self.verticalAlignment == BAVerticalAlignmentBottom) { 156 | tr.origin.y += rint(hd); 157 | } 158 | tr = UIEdgeInsetsInsetRect(tr, self.textInsets); 159 | [super drawTextInRect:tr]; 160 | } 161 | 162 | - (void)drawBezel { 163 | switch (self.bezel) { 164 | case BALabelBezelNone: 165 | break; 166 | case BALabelBezelRound: { 167 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 168 | CGContextSaveGState(ctx); 169 | CGContextSetLineWidth(ctx, MAX(1, self.bezelLineWidth)); 170 | if (self.bezelColor) { 171 | [self.bezelColor setStroke]; 172 | } 173 | CGPathRef path = CGPathCreateRoundBezel(self.bounds, self.bezelLineWidth); 174 | CGContextAddPath(ctx, path); 175 | CGPathRelease(path); 176 | CGContextStrokePath(ctx); 177 | CGContextRestoreGState(ctx); 178 | break; 179 | } 180 | case BALabelBezelRoundSolid: { 181 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 182 | CGContextSaveGState(ctx); 183 | if (self.bezelColor) { 184 | [self.bezelColor setFill]; 185 | } 186 | CGPathRef path = CGPathCreateRoundBezel(self.bounds, self.bezelLineWidth); 187 | CGContextAddPath(ctx, path); 188 | CGPathRelease(path); 189 | CGContextFillPath(ctx); 190 | CGContextRestoreGState(ctx); 191 | break; 192 | } 193 | } 194 | } 195 | 196 | - (void)drawRect:(CGRect)rect { 197 | [self drawBezel]; 198 | [super drawRect:rect]; 199 | } 200 | 201 | - (void)sizeToFitInWidth { 202 | [self sizeToFitInWidthMaxHeight:CGFLOAT_MAX]; 203 | } 204 | 205 | - (void)sizeToFitInWidthMaxHeight:(CGFloat)maxHeight { 206 | const CGFloat w = self.bounds.size.width; 207 | 208 | _fit++; 209 | _fitMaxWidth = w; 210 | _fitMaxHeight = maxHeight; 211 | 212 | CGSize s = [self sizeThatFits:CGSizeMake(w, maxHeight)]; 213 | 214 | _fit--; 215 | 216 | CGRect frame = self.frame; 217 | frame.size.height = s.height; 218 | self.frame = frame; 219 | } 220 | 221 | @end 222 | --------------------------------------------------------------------------------